This page contains a reference of basic Docker commands. This list is by no means exhaustive, essentially updated as I find things I need.
Command |
Description |
docker COMMAND --help |
Get help with commands, start here 😎 |
Containers
Starting, Stopping and Removing Containers
Command |
Description |
docker start -a |
Start a container logging stdout/err to console |
docker start -i |
Start a container and attach stdin (interactive) |
docker stop $container |
Start a container and attach stdin (interactive) |
docker container rm $container --force |
Stop and remove a container |
docker container prune |
Delete stopped containers |
Get Info About Containers
Command |
Description |
docker container ls |
List containers, only shows running containers |
docker container ls -a |
List containers (any state) |
docker container ls -l |
List the latest container created (any state) |
Interact With Containers (Shells / Scripting)
Command |
Description |
docker exec -it $container bash |
Jump into a container with an interactive bash shell (assumes bash is installed on container) |
docker exec -tty $container ~/your_script.sh |
Get an interactive shell for a shell script requiring input |
docker exec -d $container ~/your_script.sh |
Run script in container, no input, in background |
Viewing Container Logs
Command |
Description |
docker logs $container |
Output logs for container |
docker logs -f $container |
Follow docker log output (live) |
Images
Get Info About Images
Command |
Description |
docker images |
List images downloaded |
docker rmi $imageId --force |
Remove an image |
docker pull $image:tag |
Pull an image from a repository |
Super Handy Stuff
Command |
Description |
docker stop $(docker ps -a -q) |
Stop all running containers |
docker rm -f $(docker ps -a -q) |
Stop and remove all containers |
docker rmi $(docker images -q) |
Remove all images |
References: