T
Docker Cheat Sheet
Docker Cheat Sheet
The following commands may be useful to students in SE courses at MSOE. You
may need to put sudo in front of each:
- Check Docker is installed and working:
$ docker run hello-world
- Start up a container with a Bash prompt:
$ docker run -i -t ubuntu /bin/bash
- List running containers:
$ docker ps
- List all containers, including ones that have terminated:
$ docker ps -a
- Deleting containers that are not currently: running
$ docker rm $(docker ps -aq)
- Purging old images (that are no longer in use; this will result
in forcing them to be downloaded again when you reference them):
$ docker image prune -a
- Deleting all stopped images; this subsumes the image prune command:
$ docker system prune -a
- Removing all images as well; it appears you need this plus the prune
operation to delete all containers. Executing this can free up a lot of
space on your drive.
$ docker rmi $(docker images -q)
The docker images -q command lists just the ids (with no other
columns), and the $(...) turns that list into command-line
arguments.
- Build a Docker image from a Dockerfile, get it's id number, and then
restart it with a Bash prompt so you can explore the container:
$ docker build ./
$ docker ps -a
$ docker run -t -i XXXXXX /bin/bash
where the XXXXXX is the image id (such as 997485f46ec4)
from the second column
of the ps -a output. Note the status can give you an idea of how
long ago you ran the container.