Cannot log into SQL Server in mssql-server-linux container

前端 未结 2 908
孤街浪徒
孤街浪徒 2021-01-24 02:11

I am begrudgingly performing the soul-draining task of trying to use Microsoft SQL Server in a docker container, and am using the mssql-server-linux box provided by Microsoft. B

相关标签:
2条回答
  • 2021-01-24 02:42

    Does ./startup.sh have the execute permission?

    You can find out if you run docker-compose up, instead of docker-compose up -d.


    Here's an idea (inspired by this answer):

    Set the execute permission before you build the image:

    chmod +x ./startup.sh
    docker build .
    

    Docker will retain the execute permission on ./startup.sh when it copies the file.

    0 讨论(0)
  • 2021-01-24 02:49

    You're starting SQL Server in the background by using the &. Because of this your sqlcmd will start immediately after starting SQL Server and not wait until it's ready to accept connections.

    Usually you could solve this by using the double ampersand &&. By using && the second command won't start before the first command completed succesfully. However, SQL Server is a long running proces so your second command will never start.

    You can solve this by adding a sleep command after starting SQL Server.

    /opt/mssql/bin/sqlservr & sleep 30 && /opt/mssql-tools/bin/sqlcmd -S localhost etc.
    

    The sqlcmd will execute 30 seconds after starting SQL Server. If SQL Server is still not available try to up the sleep time.

    After the sqlcmd is finished the docker container will stop because there is no more foreground process. SQL Server is running the background and docker requires an active foreground process.

    Add the wait command to start waiting for the SQL Server process again.

    /opt/mssql/bin/sqlservr & sleep 30 && /opt/mssql-tools/bin/sqlcmd -S localhost etc. && wait
    

    disclaimer I just started working with Linux and Docker myself so there might be better solutions.

    0 讨论(0)
提交回复
热议问题