1

I need sql server container with some database. I've prepared the following dockerfile:

FROM microsoft/mssql-server-linux:latest
ENV ACCEPT_EULA Y
ENV SA_PASSWORD yourStrong(!)Password
WORKDIR sqlserver
COPY load_db.sh load_db.sh
COPY /resources/sql/ sql
ENTRYPOINT ./load_db.sh

So it runs load_db.sh:

#!/usr/bin/env bash

SERVER_OUT=/var/log/sqlserver.out
TIMEOUT=90
/opt/mssql/bin/sqlservr &>${SERVER_OUT} &

function server_ready() {
    grep -q -F 'Recovery is complete.' ${SERVER_OUT}
}

echo 'Wait until Microsoft SQL Server is up'
for (( i=0; i<${TIMEOUT}; i++ )); do
    sleep 1
    if server_ready; then
        break
    fi
done
echo 'Microsoft SQL Server is up'

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${SA_PASSWORD} -Q "CREATE DATABASE MarketDataService;"
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${SA_PASSWORD} -d MarketDataService -i sql/2018.0100.000000001.Add_Layout_table.sql

To run it I've prepared the followinf docker-compose file:

services:
  db:
    build:
      context: .
      dockerfile: Dockerfile-db
    ports:
    - 1433:1433

When I try to run docker-compose up --build it looks okay. I have output:

db_1       | Wait until Microsoft SQL Server is up
db_1       | Microsoft SQL Server is up
db_1       |
db_1       | (3 rows affected)

But after it is exited...

amptest_db_1 exited with code 0

To solve it I've tried to add tty: true but it doesn't make sense. The same output. How can I keep alive my container by docker-compose? Here I've found tail -F anything. It works but looks terrible. Is there a better way?

Upd: I've stayed with tail -F '/var/log/sqlserver.out'

Serg046
  • 1,043
  • 1
  • 13
  • 42

0 Answers0