I'm trying to setup MSSQL at Docker at Windows 10, but for some reason it started shutting down my container
I've been using it like that for months, but now I have no idea what's happening
C:\Users\user\
λ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
C:\Users\user\
λ docker login
Authenticating with existing credentials...
Login Succeeded
C:\Users\user\
λ docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>123' -p 1433:1433 --name sql -d mcr.microsoft.com/mssql/server:2017-latest
337e5efb35f0bf4b465181a0f8be4851b12f353a3a8710ddf817d2f501e5fea
C:\Users\user\
λ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
347q5effb3cf0 mcr.microsoft.com/mssql/server:2017-latest "/opt/mssql/bin/sqls…" 3 seconds ago Up 2 seconds 0.0.0.0:1433->1433/tcp sql
C:\Users\user\
λ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
347q5effb3cf0 mcr.microsoft.com/mssql/server:2017-latest "/opt/mssql/bin/sqls…" 6 seconds ago Exited (1) 2 seconds ago sql
C:\Users\user\
λ docker start sql
sql
C:\Users\user\
λ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
347q5effb3cf0 mcr.microsoft.com/mssql/server:2017-latest "/opt/mssql/bin/sqls…" 14 seconds ago Up 2 seconds 0.0.0.0:1433->1433/tcp sql
C:\Users\user\
λ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
347q5effb3cf0 mcr.microsoft.com/mssql/server:2017-latest "/opt/mssql/bin/sqls…" 16 seconds ago Exited (1) 1 second ago sql
docker logs sql
shows
The SQL Server End-User License Agreement (EULA) must be accepted before SQL
Server can start. The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746388.
You can accept the EULA by specifying the --accept-eula command line option,
setting the ACCEPT_EULA environment variable, or using the mssql-conf tool.
The SQL Server End-User License Agreement (EULA) must be accepted before SQL
Server can start. The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746388.
You can accept the EULA by specifying the --accept-eula command line option,
setting the ACCEPT_EULA environment variable, or using the mssql-conf tool.
Anybody has an idea what may be wrong?
When running Linux containers from Windows command line/Powershell, the environmental options (-e) require double quotes
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong!Passw0rd>123" -p 1433:1433 --name sql -d mcr.microsoft.com/mssql/server:2017-latest
Related
I have downloaded the SQL Server docker container onto my mac.
I downloaded the container using the following command from terminal
docker pull mcr.microsoft.com/mssql/server:2019-latest
I was then able to run the container using the following command
docker run -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=MyStrongPassword’ -p 1433:1433 –name sql2019_latest -d mcr.microsoft.com/mssql/server:2019-latest
However I am finding that after taking my mac out of sleep/reboot, the image is always stopped
If I run
docker images
I get the following
REPOSITORY TAG IMAGE ID CREATED SIZE
mcr.microsoft.com/mssql/server 2019-latest 80bdc8efc889 4 weeks ago 1.55GB
And when I run
docker ps
I then get nothing returned
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
I am trying to start the image, and I can start the image if I do it via the Docker Desktop, but I want to know what I should do to get the image started from a command line
I tried
docker run mcr.microsoft.com/mssql/server:2019-latest
and I get this in response
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
The SQL Server End-User License Agreement (EULA) must be accepted before SQL
Server can start. The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746388.
You can accept the EULA by specifying the --accept-eula command line option,
setting the ACCEPT_EULA environment variable, or using the mssql-conf tool.
I then tried
docker run mcr.microsoft.com/mssql/server:2019-latest --accept-eula
and I get this response:
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
/opt/mssql/bin/permissions_check.sh: line 59: exec: --: invalid option
exec: usage: exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
What am I doing wrong to start my container from starting from the command line
*** UPDATE ****
Following the reply by Jamie F I did the following:
I ran the docker ps -a command
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cac05db1aac7 mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 38 minutes ago Exited (2) 38 minutes ago agitated_cohen
0327940b7393 mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 39 minutes ago Exited (2) 39 minutes ago focused_mclean
ad077064a63a mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 41 minutes ago Exited (1) 41 minutes ago objective_torvalds
c9809150f9d1 mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 2 days ago Exited (255) 44 hours ago 0.0.0.0:1433->1433/tcp, :::1433->1433/tcp mssql2019
So I can see that there are 4 stopped containers, three with random names, but one with the name mssql2019
when I ran
docker start mssql2019
Then my image started
This is different from the name I thought I was giving the container, but in my instance I have been able to do what I required
I wanted to clean up the containers so I ran the following commands
docker rm cac05db1aac7
docker rm 0327940b7393
docker rm ad077064a63a
now when I run docker ps I can see my running image
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c9809150f9d1 mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 3 days ago Up 4 minutes 0.0.0.0:1433->1433/tcp, :::1433->1433/tcp mssql2019
and when I run docker ps -a I can see only one instance of the container
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c9809150f9d1 mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 3 days ago Up 3 minutes 0.0.0.0:1433->1433/tcp, :::1433->1433/tcp mssql2019
When you first ran this container, you downloaded the image from the docker registry. Multiple instances of the container can be run from that image. docker ps shows running containers by default. You will see your stopped container if you run docker ps -a
To start a stopped container, you can run the command docker start <container_name or ID> so in your case:
docker start sql2019_latest
(See where you assigned that name when you first ran the container?)
docker stop sql2019_latest will stop it as well.
In your case, the container (sql2019_latest) and the container image (mcr.microsoft.com/mssql/server:2019-latest) have very similar names. But that is not always the case. If you don't provide a name when you run the container, docker will create one for you, by combining a couple of odd words. Knowing when you are working with the image and when you are working with the container will help you a bunch.
Specify a --restart parameter on the docker run command to restart the container after a reboot. The example below will automatically restart it unless it was stopped before the reboot.
docker run -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=MyStrongPassword’ -p 1433:1433 –name sql2019_latest -d --restart unless-stopped mcr.microsoft.com/mssql/server:2019-latest
Command
docker pull mcr.microsoft.com/mssql/server:2019-latest
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=123456a#' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
docker logs -f 1b2ce04432883df593535157999ae3d2996620155b71e0e1d9fd25e8b2e60628
Document: https://hub.docker.com/_/microsoft-mssql-server
I see my error
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
The SQL Server End-User License Agreement (EULA) must be accepted before SQL
Server can start. The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746388.
You can accept the EULA by specifying the --accept-eula command line option,
setting the ACCEPT_EULA environment variable, or using the mssql-conf tool.
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
The SQL Server End-User License Agreement (EULA) must be accepted before SQL
Server can start. The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746388.
You can accept the EULA by specifying the --accept-eula command line option,
setting the ACCEPT_EULA environment variable, or using the mssql-conf tool.
It is an error in reference document (at https://hub.docker.com/_/microsoft-mssql-server ).
Fix it
Use " " , not ' '
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=123456a#" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
Another reference document: https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash#pullandrun2019
See more at https://github.com/microsoft/mssql-docker/issues/199#issuecomment-346092077
My Docker linux SQL Server is not working today at my machine.
I am not sure if this is firewall (I have off them all), or Docker settings (as I just upgraded to the latest Docker version), or a Docker SQL Server issue (but this was working fine on the same machine earlier).
Could anyone help?
I have tried using bash,
/opt/mssql-tools/bin/sqlcmd -S localhost,8010 -U SA -P Test123!
Error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
The docker compose file
version: '3'
services:
mssql:
network_mode: lsvc
image: microsoft/mssql-server-linux:2017-latest
container_name: mssql
hostname: mssql
volumes:
- ./.db:/var/opt/mssql/
- /var/opt/mssql/data
- ./sqlinit.sql:/scripts/sqlinit.sql
ports:
- 8010:1433
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=Test123!
command:
- /bin/bash
- -c
- |
# Launch MSSQL and send to background
/opt/mssql/bin/sqlservr &
# Wait for it to be available
echo "Waiting for MS SQL to be available"
/opt/mssql-tools/bin/sqlcmd -l 30 -S mssql -h-1 -V1 -U sa -P Test123! -Q "SET NOCOUNT ON SELECT \"YAY WE ARE UP\" , ##servername"
is_up=$$?
while [ $$is_up -ne 0 ] ; do
echo -e $$(date)
/opt/mssql-tools/bin/sqlcmd -l 30 -S mssql -h-1 -V1 -U sa -P Test123! -Q "SET NOCOUNT ON SELECT \"YAY WE ARE UP\" , ##servername"
is_up=$$?
sleep 1
done
# Run every script in /scripts
# TODO set a flag so that this is only done once on creation,
# and not every time the container runs
#for foo in /scripts/*.sql
/opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P Test123! -l 30 -e -i /scripts/sqlinit.sql
#done
# So that the container doesn't shut down, sleep this thread
sleep infinity
I would suspect that the mssql instance had failed to start.
Looking at your docker file when the server fail to start it runs into in infinite loop. I would advice you to limit the number of retries on the loop so you will have an indication that the server is failing on startup.
Or better consider the use of the HEALTHCHECK option and not the loop script
see https://blog.couchbase.com/docker-health-check-keeping-containers-healthy/
To troubleshooting the problem try
docker logs <mssql-container-id>
if this doesn't provide enough information try connecting to the container as this was a simple machine.
docker exec -it <mssql-container-id> bash
Look for errors in /var/opt/mssql/log/errorlog
See https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-troubleshooting-guide?view=sql-server-ver15
i found the root cause, it is not due to docker mssql linux
but the latest Docker Desktop Community 2.2.0.0
after uninstall it then downgrade to old version, Docker Desktop Community 2.1.0.5.
it is working now, connect to mssql success.
not sure what is new in latest docker desktop, anyway...i will use old version now.
also one important point to take note, the ".db" folder (windows path where the yml file reside), must deleted before build the docker image.
I have a problem followng [this tutorial](https://hub.docker.com/r/microsoft/mssql-server-linux/
) where I try to connect to my docker hosted MSSQL via sqlcmd.
I executed the following in PowerShell from windows:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e \
'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it \
-d microsoft/mssql-server-linux:latest /bin/bash
Note: "-it" and "/bin/bash" is added due to docker will be stopped automatically if there is no any activity detected.
I ran docker container ls -a to verify it is running:
docker container Is -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92cfc504ab70 microsoft/mssql-server-linux:latest "/bin/bash" 27 minutes ago Up 27 minutes 0.0.0.0:1433->1433/tcp mssql
I ran telnet local-ip:1433 on my host, it is working fine.
Problem lies when I do the following:
docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa \
-P yourStrong(!)Password
Error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout
expired. Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP
Provider: Error code 0x2749. Sqlcmd: Error: Microsoft ODBC Driver 17
for SQL Server : A network-related or instance-specific error has
occurred while establishing a connection to SQL Server. Server is not
found or not accessible. Check if instance name is correct and if SQL
Server is configured to allow remote connections. For more information
see SQL Server Books Online..
I also tried to connect in using powershell via my host
Link:https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker
Command:
sqlcmd -S 192.168.0.110,1433 -U SA -P yourStrong(!)Password
Note: 192.168.0.110(got this from running ipconfig in host machine.)
Any help ?
I found out the problems after some trials and errors, and re-reading the documents. I should use double quotes for the arguments when I executed my command in PowerShell.
I was looking into the wrong direction. Initially I executed the command:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e \
'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d \
microsoft/mssql-server-linux:latest
Container stopped automatically by itself every time it starts.
Then, I did some googling and found:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e \
'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it -d \
microsoft/mssql-server-linux:latest /bin/bash
It seemed fine on the surface. It got executed successfully in PowerShell. It didn't stop automatically anymore.If I dig deeper using
docker container logs mssql
to see the log for mssql. No error given, just that I don't see a lots of info given, which led me to think that there were no problems in my command.
But the right way to run these commands is using double quotes.
Link: https://hub.docker.com/r/microsoft/mssql-server-linux/
IMPORTANT NOTE: If you are using PowerShell on Windows to run these commands use double quotes instead of single quotes.
E.g.
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrong!Passw0rd" -p 1401:1433 --name sql1 -d microsoft/mssql-server-linux:2017-latest
I am also able to login using SSMS with:
Server name: Hostip,1401
Username: sa
Password:yourpassword
Try 127.0.0.1 or 0.0.0.0 instead of localhost
For example :
docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P 'yourStrong(!)Password'
docker run command syntax is the following:
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
When you execute the command:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it -d microsoft/mssql-server-linux:latest /bin/bash
/bin/bash in the end overrides CMD layer defined in the Dockerfile of microsoft/mssql-server-linux image.
So, just start a container without any additional command in the end:
$ docker run -e 'ACCEPT_EULA=Y' --name mssql -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it -d microsoft/mssql-server-linux:latest
And now you are able to access a MSSQL:
$ docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'yourStrong(!)Password'
1>
I'm new to Docker and I also I had the same issue when I try to connect to the SQL Server container from my application(or sqlcmd app container from Microsoft) which is also running in another Docker container. It looks like each container gets its own subnet IP address, so 'localhost' would never work if you're trying to connect to the SQL from another container.
The command below will give you the full list of IP addresses in the bridge network. You can specify the IP directly in the connection string.
docker network inspect bridge
From your message, it looks the server is not configured to access remotely. Can you follow the way mentioned below to enable it?
Using SSMS (SQL Server Management studio):
In Object Explorer, right-click a server and select Properties.
Click the Connections node.
Under Remote server connections, select the Allow remote connections to this server check box.
Thanks,
Ananda Kumar J.
I want to run sql-server on a mac os x computer. I have successfully build and start a docker container this way:
docker pull microsoft/mssql-server-linux
docker create -v /var/opt/mssql --name volume_mssql microsoft/mssql-server-linux /bin/true
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=SuperPa3ss#1' -p 1433:1433 --volumes-from volume_mssql -d --name sqlserver1 microsoft/mssql-server-linux
It works fine. But i do not know what to do to restart this containers when the computer restarts...
Thanks
** edit **
if i type:
$ docker start volume_mssql
$ docker start sqlserver1
I have no error message, but i see the containers are "exited"
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5721868bbe1 microsoft/mssql-server-linux "/bin/sh -c /opt/mss…" 15 hours ago Exited (255) 3 minutes ago sqlserver1
e5b88bb02a1b microsoft/mssql-server-linux "/bin/true" 15 hours ago Exited (0) 4 minutes ago volume_mssql
** edit **
$ docker container logs sqlserver1
Dump collecting thread [6] hit exception [6]. Exiting.
Dump collecting thread [7] hit exception [6]. Exiting.
For Autostart, docker container adds --restart always in docker run command.
Change your command to:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=SuperPa3ss#1' --restart always -p 1433:1433 --volumes-from volume_mssql -d --name sqlserver1 microsoft/mssql-server-linux
Your container will start automatically when you restart the docker and PC.
From Terminal:
$ docker pull microsoft/mssql-server-linux
$ docker run -d — name sql_server_demo -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=Dev#998877’ -p 1433:1433 microsoft/mssql-server-linux
$ dokcer image ls
Now Download azure data studio from here,
https://learn.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15
Connect to SQL Server
Server: localhost
Authentication Type: SQL Login
User Name: sa
Password: Dev#99887
Steps by steps:
https://medium.com/macoclock/run-mssql-on-mac-using-docker-39460da701b9
You can find the container name by running: docker ps -a and use the name to start it using docker start <container-name>.
Alternatively, you can specify the container to start automatically by adding --restart always to the run command. This will make the container autostart once you restart the PC.