Open logcorner opened 6 years ago
docker exec into your running container and see if if sqlservr is even running: by using top
docker exec -it
/bin/bash root@ > top also try starting your container interactively by not passing -d to docker run so you can see the output as SQL Server starts up.
thank you, @twright-msft for your answer
docker exec -it sql1 "bash" /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Passw0rd
CREATE DATABASE TestDB
SELECT Name from sys.Databases
works fine .
Everything works mannualy but if i use the dockerfile, it throws an exception Sqlcmd: Error
Maybe try without the -d parameter in your .sh file? Also try using 127.0.0.1 instead of localhost.
You can try this
RUN ( /opt/mssql/bin/sqlservr --accept-eula & ) | grep -q "Service Broker manager has started" \ && /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Passw0rd -d master -i SqlCmdScript.sql
I have the following error @vu-le
./setup-database.sh: line 7: syntax error near unexpected token `/opt/mssql/bin/sqlservr'
./setup-database.sh: line 7: `RUN(/opt/mssql/bin/sqlservr --accept-eula & ) | grep -q "Service Broker manager has started" '
Here is the content of setup-database.sh
echo 'Please wait while SQL Server 2017 warms up'
sleep 10s
echo 'Initializing database after 30 seconds of wait'
#/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'MyC0m9l&xP@ssw0rd' -d master -i initialize-database.sql
RUN(/opt/mssql/bin/sqlservr --accept-eula & ) | grep -q "Service Broker manager has started"
&& /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'MyC0m9l&xP@ssw0rd' -d master -i initialize-database.sql
echo 'Finished initializing the database'
NB : Im using docker for windows and linux container
FROM microsoft/mssql-server-linux ENV SA_PASSWORD=Passw0rd ENV ACCEPT_EULA=Y COPY SqlCmdScript.sql SqlCmdScript.sql RUN(/opt/mssql/bin/sqlservr --accept-eula & ) | grep -q "Service Broker manager has started" && /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd' -d master -i SqlCmdScript.sql
Hi, @vu-le thank you, Running the command on your docker file : docker build –t testsql/sqldb . I have the following Sending build context to Docker daemon 6.144kB Error response from daemon: Dockerfile parse error line 5: unknown instruction: RUN(/OPT/MSSQL/BIN/SQLSERVR
can you run it in a bash shell ?
using bash @vu-le
FWIW: the response of vu-le had some syntax errors, if you paste the following code, it should work
FROM microsoft/mssql-server-linux
ENV SA_PASSWORD=Passw0rd
ENV ACCEPT_EULA=Y
COPY SqlCmdScript.sql SqlCmdScript.sql
RUN (/opt/mssql/bin/sqlservr --accept-eula & ) | grep -q "Service Broker manager has started" && /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd' -d master -i SqlCmdScript.sql
This is my script to create logins and attach dbs on docker run:
docker run -it -p 1433:1433 --name mssql -v C:\docker-db:/var/opt/mssql mssql
FROM mcr.microsoft.com/mssql/server:2017-latest
ENV SA_PASSWORD=Passw0rd
ENV ACCEPT_EULA=Y
COPY ./CreateLogins.sql .
COPY ./AttachDb.sql .
COPY ./EntryPoint.sh .
COPY ./SqlCmdStartup.sh .
RUN chmod +x ./SqlCmdStartup.sh
CMD /bin/bash ./EntryPoint.sh
EntryPoint.sh
#!/bin/bash
./SqlCmdStartup.sh & /opt/mssql/bin/sqlservr
SqlCmdStartup.sh
#!/bin/bash
set -e
wait_time=90s
password=Passw0rd
# wait for SQL Server to come up
echo importing data will start in $wait_time...
sleep $wait_time
echo running CreateLogins...
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $password -i CreateLogins.sql
echo running AttachDb...
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $password -i AttachDb.sql
exec "$@"
Hi. I have same problem with a little difference. I'm using GitLab CI to do integration for my mssql using the docker image. When I run a mssql-container myself and try to execute a command using "sqlcmd", it's fine. But as GitLab CI runs a container and tries to connect to the DB or something else, it fails with same login error.
Can anyone help me?
I am using @vitalybibikov code. it works fine. when I use CMD it hangs. when I use entrypoint, it works fine. But finishes script and hangs. Not exiting the container. what is the problem?
Hi, I try this tutorial to run a sqlserverlinux image and insert some data and i have always this error ; Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
I use docker for windows 18.06.0-ce
SqlCmdScript.sql
SqlCmdStartup.sh
entrypoint.sh
Dockerfile
I try the tutorial : Data Points - On-the-Fly SQL Servers with Docker) Do you have any idea ?