ms sql server on mac os x with docker - sql-server

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.

Related

Connect with FTP to Docker Container

I'm new to Docker and I'm using this Microsoft SQL Server Docker Image
sudo docker pull mcr.microsoft.com/mssql/server:2019-latest
I've run the container on my linux server with this command which is from the microsoft doc:
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong#Passw0rd>" \
-p 1433:1433 --name sql1 --hostname sql1 \
-d mcr.microsoft.com/mssql/server:2019-latest
I can connect with ssh when I'm on my server with this command:
sudo docker exec -it sql1 "bash"
My problem is that I can't figure out how I can connect to this container with FTP.
I thought installing ftp on the image and then run with something like:
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong#Passw0rd>" \
-p 1433:1433 -p 21:21 --name sql1 --hostname sql1 \
-d mcr.microsoft.com/mssql/server:2019-latest
But I can't run it again without removing the image.
I Would be glad if someone could help me.
I did not found a way to get an FTP Access but the main purpose was to be able to move a file from the host into the container.
The way to do that is as simple as a ssh cp
sudo docker cp foo.txt containerID:/foo.txt
Thanks for the answers
You are not editing the image but the container that you create with that command.
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong#Passw0rd>" \
-p 1433:1433 -p 21:21 --name sql1 --hostname sql1 \
-d mcr.microsoft.com/mssql/server:2019-latest
Just run that command to create your container and use that container via
docker start sql1
and
sudo docker exec -it sql1 "bash"
and if you want to have an image of your container after you edited your Container, use the
docker commit sql1
or so. (You might read the documentation on docker commit for correct syntax.)
UPDATE:
As of the comments below, I'd like to recommend you to get yourself confident with the docker file usage instead of docker commit.

Problem Optimizing Docker Container Start With SqlServer on MacBook OSX

I'm a Docker newbie and have managed to create simple steps to create, start and load an image running sqlserver with a database backup. For me, it's three steps now.
docker pull mcr.microsoft.com/mssql/server:2019-latest
docker run --name SQL19c -p 1433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=xxxx" -v /Users/useraccount/sql:/sql -d mcr.microsoft.com/mssql/server:2019-latest
docker exec -it SQL19c /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'xxxx' -Q 'RESTORE DATABASE svcodecamp FROM DISK = "/sql/sv-small-2019.bak" WITH MOVE "361684_codecamp08_dat" TO "/var/opt/mssql/ata/codecamp08_dat.mdf", MOVE "361684_codecamp08_log" TO "/var/opt/mssql/data/codecamp08_log.mdf"'
This is on my macbook running OSX which I reboot frequently so I need to do this everytime I need to use SqlServer.
Questions with this:
1) Each time I do this, I have to increment the SQL19c to Sql19d (or next letter of alphabet) because I get error saying name in use. How to re-use same name?
2) If I rm the container, it needs to repull the full image (1gig). I need to just start it and reload the data, not pull the full image
3) Is there a more optimum way to start SqlServer and load the data without using too much of my battery every time I reboot my computer or restart docker?
(notice my backup file is on a docker share so I don't need to recopy that in)
This is because you already have a container with this name. Try to execute the command:
docker container list -a
If you repull the image I think you remove the image NOT the container for remove the container you must run
docker container rm SQL19x
The way is to restart the container, drop database and then restore the database
Run ONCE: This create a SQL19x container
docker pull mcr.microsoft.com/mssql/server:2019-latest
docker run --name SQL19x -p 1433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=xxxx" -v /Users/useraccount/sql:/sql -d mcr.microsoft.com/mssql/server:2019-latest
Now each time you restart the machine you must run the command below to start the container and restart the database.
docker container start SQL19x
docker exec -it SQL19x /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'xxxx' -Q 'DROP DATABASE svcodecamp'
docker exec -it SQL19x /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'xxxx' -Q 'RESTORE DATABASE svcodecamp FROM DISK = "/sql/sv-small-2019.bak" WITH MOVE "361684_codecamp08_dat" TO "/var/opt/mssql/ata/codecamp08_dat.mdf", MOVE "361684_codecamp08_log" TO "/var/opt/mssql/data/codecamp08_log.mdf"'
If you want to have a clean shutdown before to poweroff your machine execute
docker container stop SQL19x

SQL Server in Docker network: executable file not found in $PATH": unknown

I want to create a Docker network and use it with a SQL Server.
Here is what I've done:
# Setup Network
sudo docker network create -d bridge dockerapi-dev
# Setup MSSQL Server
sudo docker pull mcr.microsoft.com/mssql/server
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=password" -p 1433:1433 -d mcr.microsoft.com/mssql/server --network dockerapi-dev --name mssqlserver
Under sudo docker network ls my network "dockerapi-dev" shows up as "bridge" as I want it to.
With the last command, I get the following error message:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"--network\": executable file not found in $PATH": unknown.
I would be grateful if someone could help me.
The error message is a hint that it thinks --network is part of the image to run.
Re-order your arguments like this (the image to run is last):
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=password" -p 1433:1433 -d --network dockerapi-dev --name mssqlserver mcr.microsoft.com/mssql/server

I created and run a sqlserver container, I stop it and I don't know how to run it again?

I created and run a SQL Server docker container. I stop it and I don't know how to start it again.
I use this command line:
sudo docker run --name sql_server_db -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=TEST_XXXXXXX' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest
Type the following command to start the image, where <container_name> is the name of the image:
docker start <container_name>

Failed to connect to docker hosted MSSQL

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.

Resources