LLI Wiki — My Digital Knowledge Base

Docker: useful commands and SQL Server on Linux

Common Docker commands (stopped containers, shells, image updates, container IP) and an example SQL Server 2019 container on Linux.

A reference of the most useful everyday Docker commands, with an example running SQL Server 2019 on Linux in a container.

Restart and reattach a stopped container

docker start $(docker ps -q -l)    # restarts the most recently created container, in the background
docker attach $(docker ps -q -l)   # reattaches the terminal and stdin to the container

List containers

sudo docker ps -a

Open a shell in a container

Running container:

docker exec -it <container name or ID> /bin/bash

Temporary container, removed when you exit:

docker run -i -t --rm centos /bin/bash

Update images

Pull again every local image:

docker images | grep -v REPOSITORY | awk '{print $1}' | xargs -L1 docker pull

Get the IP address of a container

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container name or ID>

SQL Server 2019 on Linux in Docker

Pull the image and create the container, with a host folder to keep the data:

docker pull mcr.microsoft.com/mssql/server:2019-latest

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>" \
   -p 1433:1433 --name sql1 \
   -v /path/on/host/sql-data:/var/opt/mssql \
   -d mcr.microsoft.com/mssql/server:2019-latest

The SA password must meet the SQL Server password complexity policy.

Connect with sqlcmd from inside the container:

sudo docker exec -it sql1 /opt/mssql-tools/bin/sqlcmd \
   -S localhost -U SA -P '<YourStrong!Passw0rd>' \
   -Q 'SELECT @@VERSION'

Read the logs:

docker logs sql1
sudo docker exec -it sql1 cat /var/opt/mssql/log/errorlog

Notes

Mastodon LLIMastodon SocialFosstodon