Docker Composer & Dockerfile “Artiste Palette & Easel” of Commands & Template Strings for Command Line (Copy/Paste)

Disclaimer: This is a work in progress, as always. I’ll be adding more specifics to docker versions and separating the Dockerfile and docker-compose.yml contents eventually. For now, this is just the stuff that I need for quick copy/paste onto the command line (so I’m not constantly looking it up or fishing through my history | grep “blablah”).

I found myself using the same similar commands over & over again as I began to use docker-composer.yml and Dockerfiles to deploy applications, so I made this easy reference list for simple copy & paste from some of the CLI history I’ve accumulated on Debian, Ubuntu & CentOS hosts (eg AWS EC2s, Azure VMs, VPSs, VMware VMs, Virtualbox VMs, Vagrant boxes, etc)

Show all docker containers (included stopped containers)

docker container ps -a

Remove all STOPed docker containers (that are not running)

docker container prune

Remove all “dangling” docker images (that are just taking up space)

docker rmi $(docker images -q --filter "dangling=true")

Remove all “intermediate” docker images

docker rmi -f $(docker images -q --filter label=stage=intermediate)

Show all docker images

docker images

Remove docker image (** represents image name[s])

docker rmi -f **

Build image from Dockerfile (“example image name:Dockerfile”)

docker build -t "debian-build-demo0:Dockerfile"

Run a docker container from a docker image for web server

docker run -d -p 8080:8080 --name "debian-build-demo0" debian-build-demo0

Find IP address of docker container (eg container name: mariadb-build-demo0)

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mariadb-build-demo0

Remove all docker volumes not currently in use

docker volume prune

Remove all docker networks not currently in use

docker network prune