docker

abstract

Docker is a software platform which builds and runs containers. Containers can simulate other computers with different software installed. Development containers can help increase reproducibility and decrease coupling.

basics

commands

docker build myimage . build myimage from a Dockerfile in the current folder
docker image ls show all images
docker image rm myimage delete myimage
docker network ls show all networks
docker ps --all show all containers
docker run myimage run a container from myimage
docker run myimage ls -la run ls -la in a container from myimage
docker system prune delete unused docker objects
docker volume ls show all volumes

dependencies

examples

Build an image named myimage:v2 from a Dockerfile in some/folder:

docker build --tag myimage:v2 some/folder

Run bash interactively in a self-destructing container from the myimage:v2 image:

docker run --rm --interactive --tty myimage:v2 bash

Run the default myimage:v2 command with the current folder mounted read-only as /context:

docker run --volume "$(pwd):/context:ro" myimage:v2

Delete the myimage:v2 image and any containers using it:

docker ps --quiet --filter ancestor="myimage:v2" | xargs docker rm --force
docker image rm myimage:v2 --force

Stop all containers, then delete stopped containers and unused objects:

docker ps --quiet | xargs docker kill
docker system prune --force

faq

Where is the official documentation?
Docker docs
Dockerfile reference
docker run reference
Do containers always run as root?
No. Add a USER in a Dockerfile or call docker run with the --user option.
Can I run a container in a container?
squint
Email GitHub LinkedIn
return
© Sam Kennerly 2023. Licensed under a CC BY 4.0 license.
Built by a Quarto
with icons by Simple Icons.
samkennerly@gmail.com