The Docker commands I keep forgetting: build, run, list and clean up images and containers.

README.md PDF

Reminders

docker build .                  # build an image from the Dockerfile in this folder
docker run 1b2b66f83a77         # start a container from an image ID
docker images                   # list images
docker rmi <image>              # remove an image
docker container ls             # list running containers
docker container prune -f       # remove all stopped containers
docker image prune              # remove dangling images

docker ps -a                    # all containers, also stopped ones
docker logs -f <container>      # follow the output of a container
docker exec -it <container> sh  # open a shell inside a running container
docker run --rm -it debian bash # a throw-away container (removed when you exit)
docker system df                # how much disk space Docker uses
docker system prune             # clean up stopped containers, networks, dangling images

docker compose up -d            # start everything in compose.yaml in the background
docker compose logs -f          # follow the logs of all services
docker compose down             # stop and remove the containers

💡 On Fedora you can use Podman instead: sudo dnf install podman. The commands are the same (podman run, podman ps, …), and it runs containers without a root daemon.