Here is a list of Docker commands I find myself using frequently. Instead of having to google them each time I need one, the idea is to start collecting them in a central place. Hope you find them useful.

  • Pull an image from Docker registry
> docker pull image-name
  • Start a container from an image
> docker run -d --name webapp -p host:container image:tag
  • Stop and remove a container
> docker rm -f container-name
  • Execute command on container shell
> docker exec -it container-name /bin/bash
  • Create a volume
> docker volume create --name sqldata
  • Create a container using a volume (If you then create another container with the same volume name, the new container uses the same SQL Server data contained in the volume.)
> docker run -d --mount source=volume-name,destination=container-path --name webapp image:tag
  • Set environment flags when you run a container
> docker run -e "ACCEPT_EULA=Y" image_name
  • Start an sql server container
> docker run -d -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=MyPassword" -p 1433:1433 --name db microsoft/mssql-server-windows-express
  • Find the IP address of the container
> docker inspect db | grep "ipaddress"
  • Connect to the SQL server container from host machine
> sqlcmd -S 173.45.23.140,1433 -U SA -P Docker@Azure10
  • Launch a bash session on a clean Ubuntu container
> docker container run -it --hostname "home" --name image-dev ubuntu:latest /bin/bash