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/

Mac

brew install --cask docker

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/

APPNAME=name-of-app
REGISTRY=path-to-container-registry (e.g. acrteam.azurecr.io)
RESOURCE=name-ofresource
TAGNAME=dev-qa-prod (e.g. qarelease)

List

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

Remove

docker image rm $APPNAME-$RESOURCE
docker image rm $APPNAME-$RESOURCE1 $APPNAME-$RESOURCE2
docker image rm $APPNAME-$RESOURCE:$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}')

Build and Tag

docker build $APPNAME-$RESOURCE:$TAGNAME .
docker build --tag $APPNAME-$RESOURCE:$TAGNAME .
docker build --tag $APPNAME-$REGISTRY/$RESOURCE:$TAGNAME .

Pull

docker pull $APPNAME-$RESOURCE:$TAGNAME
docker pull $REGISTRY/$APPNAME-$RESOURCE:$TAGNAME

Tag

docker tag $APPNAME-$RESOURCE:$TAGNAME1 $REGISTRY/$APPNAME-$RESOURCE:$TAGNAME2

Push

docker push $REGISTRY/$APPNAME-$RESOURCE:$TAGNAME

Backup and replace image in repository
docker pull $REGISTRY/$APPNAME-$RESOURCE:${TAGNAME}release  && \
docker tag $REGISTRY/$APPNAME-$RESOURCE:${TAGNAME}release $REGISTRY/$APPNAME-$RESOURCE:${TAGNAME}rollback && \
docker push $REGISTRY/$APPNAME-$RESOURCE:${TAGNAME}rollback && \
docker build -t $REGISTRY/$APPNAME-$RESOURCE:${TAGNAME}release . && \
docker push $REGISTRY/$APPNAME-$RESOURCE:${TAGNAME}release
Commit a build

docker commit buildnumber $APPNAME-$RESOURCE:$TAGNAME

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

Uninstall

brew uninstall --cask docker

Uninstall Docker on Mac when completely unresponsive

sudo rm -Rf /APPNAMElications/Docker.APPNAME
sudo rm -f /usr/local/bin/docker
sudo rm -f /usr/local/bin/docker-machine
sudo rm -f /usr/local/bin/com.docker.cli
sudo rm -f /usr/local/bin/docker-compose
sudo rm -f /usr/local/bin/docker-compose-v1
sudo rm -f /usr/local/bin/docker-credential-desktop
sudo rm -f /usr/local/bin/docker-credential-ecr-login
sudo rm -f /usr/local/bin/docker-credential-osxkeychain
sudo rm -f /usr/local/bin/hub-tool
sudo rm -f /usr/local/bin/hyperkit
sudo rm -f /usr/local/bin/kubectl.docker
sudo rm -f /usr/local/bin/vpnkit
sudo rm -Rf ~/.docker
sudo rm -Rf ~/Library/Containers/com.docker.docker
sudo rm -Rf ~/Library/APPNAMElication\ Support/Docker\ Desktop
sudo rm -Rf ~/Library/Group\ Containers/group.com.docker
sudo rm -f ~/Library/HTTPStorages/com.docker.docker.binarycookies
sudo rm -f /Library/PrivilegedHelperTools/com.docker.vmnetd
sudo rm -f /Library/LaunchDaemons/com.docker.vmnetd.plist
sudo rm -Rf ~/Library/Logs/Docker\ Desktop
sudo rm -Rf /usr/local/lib/docker
sudo rm -f ~/Library/Preferences/com.docker.docker.plist
sudo rm -Rf ~/Library/Saved\ APPNAMElication\ State/com.electron.docker-frontend.savedState
sudo rm -f ~/Library/Preferences/com.electron.docker-frontend.plist