Install

Windows

See https://docs.docker.com/docker-for-windows/

Linux

Install Docker Engine and Docker Compose separately:
See https://docs.docker.com/engine/install/ubuntu/
See https://docs.docker.com/compose/install/

Basics

Common commands run from Bash or PowerShell.
docker --version --> check version
docker system prune -a --> remove everything (except running)
docker ps -aq --> show all running processes (no prompt)

Images

See https://docs.docker.com/engine/reference/commandline/build/

Build an image

docker build --tag imagename:tagname .
docker build --tag registryname.azurecr.io/imagename:tagname .

Commit build changes before push

docker commit buildnumber imagename:tagname

Pull, Tag, and Push an image

Pull image from repository
docker pull ubuntu:tagname
docker pull registryname.azure.io/imagename:tagname

Create a new tag
docker tag imagename:tagname1 registryname.azurecr.io/imagename:tagname2

Push image to repository
docker push registryname.azurecr.io/imagename:tagname

Backup and replace image in repository

docker pull registryname.azurecr.io/imagename:prodrelease && \
docker tag registryname.azurecr.io/imagename:prodrelease registryname.azurecr.io/imagename:prodrollback && \
docker push registryname.azurecr.io/imagename:prodrollback && \
docker build -t registryname.azurecr.io/imagename:prodrelease . && \
docker push registryname.azurecr.io/imagename:prodrelease
List images

docker images
docker image ls
docker images -f “dangling=true” -q

Remove image(s)

docker image rm 182712361A
docker image rm 182712361A 9934812348
docker image rm imagename:tagname
docker image prune -a

Beginning with:
docker rmi $(docker images -a | grep "^<none>" | awk '{print $3}')
docker rmi $(docker images -a | grep "^registryname" | awk '{print $3}')

Tagged with:
docker rmi $(docker images -a | grep "<none>" | awk '{print $3}')

Volumes & Networks

Create

docker network create networkname

List

docker volume
docker network

Remove

docker volume prune
docker network prune

Containers

See https://docs.docker.com/engine/reference/run/

Run a container

-it --> interactive tty
-p --> publish outside:inside ports
-e --> environment variable
-d --> detached mode
--rm --> remove running container when closed
--name --> give running container an easy to remember name
--net --> map container to Docker network name

Run image and open interactive shell
docker run -it image:tagname /bin/bash

Use a variety of flags
docker run -e 'MARIADB_ROOT_PASSWORD=password' --name containername registryname.azurecr.io/imagename:tagname
docker run -p 1521:1521 --name containername imagename:tagname
docker run -d -p 80:80 --name containername imagename
docker run -d --rm --name containername imagename:tagname
docker run -d --rm -p 3306:3306 --net wp --name containername registryname.azurecr.io/imagename:tagname

Access command line of a container

docker exec -it containername /bin/bash
docker exec -it containername /bin/sh

Access command line of a container as root user

docker exec -it -u root containername /bin/bash
docker exec -it -u 0 containername /bin/bash

List containers

docker container ls
docker container ls -a
docker container ls --all

Stop, kill, and remove running container(s)

docker container stop containername
docker container kill containername

docker container rm containername
docker container rm containername1 containername2 relaxed_sammet

More than one by variable
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)

Get serious
docker container prune -a

Docker-Compose

docker-compose up -d
docker-compose --verbose up
Docker-Compose - restart a service locally
s=servicename
docker-compose kill $s && 
docker-compose rm -f $s && \
docker-compose build $s && \
docker-compose up -d && \
docker-compose logs -f $s
Access command line of a container

docker-compose exec containername /bin/bash