Connect with FTP to Docker Container - sql-server

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.

Related

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

Connect to SQL Server instance running on playwithdocker with a local Management Studio

I'm able to run a SQL Server (for linux) instance in playwith docker
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password_01!" -p 1433:1433 --name sql1 --hostname ciccio -d microsoft/mssql-server-linux:2017-latest
and issue some commands from the terminal
docker exec -it sql1 /opt/mssql-tools/bin/sqlcmd -S ciccio -U sa -P Password_01!
However, I can't to connect to this instance from my local Management Studio.
Does anyone know how to do this? What check to see if the ports are open or the connection is reachable?
I've tried with the following address combinations:
http://ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com
http://ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com,1433
ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com
ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com,1433
the ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com are the urls provided from playwithdocker when the service is up and running

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>

ms sql server on mac os x with docker

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.

Resources