25 February,2020 by Tom Collins
I've
started working with Docker platform and managing SQL Server Containers. This list are some of the commands I execute most often when using Docker and Containers.
--Pull down a container from the Docker registry
docker pull <path-of_image>
--(generic approach)Pull down a sql server container to a valid docker installation on RHEL and run
(generic approach)
docker pull microsoft/mssql-server-linux
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=LinuxSQLServer123' -p 1433:1433 -d microsoft/mssql-server-linux
--(customised approach)Pull down a sql server container to a valid docker installation on RHEL and run
Step 1 - Mapping volume names with customised locations
**comment - data volume**
docker volume create --opt type=none --opt device=/myapps/mssql/mpdata/myapp1--opt o=bind myapp1_data
**comment - backup volume**
docker volume create --opt type=none --opt device=/myapps/mssql/mpbkp/myapp1--opt o=bind myapp1_bkp
**comment - log volume**
docker volume create --opt type=none --opt device=/myapps/mssql/mplog/myapp1--opt o=bind myapp1_log
**comment - temp volume**
docker volume create --opt type=none --opt device=/myapps/mssql/mptemp/myapp1--opt o=bind myapp1_temp
Step 2 Create the new MSSQL Container
docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=sql247' --mount source=myapp1_data,target=/var/opt/mssql/data --mount source=myapp1_bkp,target=/var/opt/mssql_bkp --mount source=myapp1_log,target=/var/opt/mssql_log --mount source=myapp1_temp,target=/var/opt/mssql_temp -p 1401:1433 --restart always --name myapp1 -e 'MSSQL_PID=Enterprise' -d microsoft/mssql-server-linux
Step 2 - Adding the SQL Server Agent
Use the added environment variable MSSQL_AGENT_ENABLED=True . Taking the above docker run command and adding the environment variable
docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=sql247' -e 'MSSQL_AGENT_ENABLED=True'--mount source=myapp1_data,target=/var/opt/mssql/data --mount source=myapp1_bkp,target=/var/opt/mssql_bkp --mount source=myapp1_log,target=/var/opt/mssql_log --mount source=myapp1_temp,target=/var/opt/mssql_temp -p 1401:1433 --restart always --name myapp1 -e 'MSSQL_PID=Enterprise' -d microsoft/mssql-server-linux
--List all Docker images
docker images
--View all containers. This will all also give you the container id
docker ps -a
--Execute a command within a container
docker exec –it <container-name> <command-name>
--Start a docker bash session,Example of connecting to a SQL Server Container
docker exec -it flamboyant_margulis "bash"
--In a bash session connect to SQL Server Instance with sqlcmd
root@jjKlMMlp:/# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "LinuxSQLServer123"
--Get Docker Logs
docker logs <container_name>
docker start <containername>
docker stop <container-name>
docker rm -f <container-name>
‘-f’ option forces the container to be removed. the alternative is to stop Container and then remove
--Docker Events . Get real time events
docker events
--Get public port of a container
docker port <container id>
--Get processes running on docker container
docker top <container id>
--Get container resource usage statistcs. Memory , CPU, net i/o , block i/o
docker stats <container id>
--Get docker changed files container's FS.
docker diff <container id>
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |