docker cli cheat sheet
Help
docker COMMAND --help
Images – base of containers
- Create:
docker build -t my-web docker/webserver-t... name (e.g.my-web) and optionally tag (e.g.my-web:latest,my-web:1.0)docker/webserver... the dir in which theDockerfileresides
- List all:
docker images - List all with intermediates:
docker images -a - List specific:
docker images my-web- Lists versions (i.e. tags) of specific image name (i.e. repository)
- Delete:
docker rmi my-web- Attention: Image must not be used by a container
Containers – do the actual work
- List running:
docker ps - List all:
docker ps -a - Remove:
docker rm <container-name>ordocker container rm <container-name>
Volumes – where containers put their data
- List all:
docker volumesordocker volume ls - Remove:
docker volume rm <volume-name>
Management
-
How to spare disk space?
- As much and as little as needed.
-
docker builder prune... removes dangling build cache- Note: Asks for confirmation
- Removes dangling build cache which are all layers that are not used in any tagged image (I suppose)
-
docker builder prune -a... removes all build cache- Note: Asks for confirmation
Understanding docker build cache
How to enforce a rebuild of a layer?
- E.g. How to enforce a fresh run of
apt update? docker build prune -adocker rmi image-id<-- won't work because it has dependent child images most likely- Temporarily add a layer before the
RUN apt update-> not working either because if I understand docker build cache correctly, this would run and build a fresh layer. However, when removing that temporary layer before, the "old" aka already cached apt update layer would be used again. So it is going to bedocker build prune -a. Well, even that didn't work. Then removing container, image and so forth didn't work either. The cached layer was still somewhere in use. Last remedy was todocker pull ubuntu:20.04(the base image). What was the problem even? apt-repo mirrors weren't reachable anymore (IP address was not reachable or something like that).