Docker Quick Reference Commands¶
All command examples are intended to be entered via the console or terminal.
Action | Command Example | Info |
---|---|---|
Attach Container | docker container attach container-name-or-id | |
Build Image | docker build -t yourusername/image-name . | |
Download Latest Image | docker pull busybox | |
List Container Ports | docker container port container-name-or-id | List port mappings for the container. |
List Container Ports | docker port container-name-or-id | List port mappings for the container. |
List Containers | docker container ls -a | Shows all containers. |
List Containers | docker ps -a | Shows all containers. |
List Containers Running | docker container ls | |
List Containers Running | docker ps | |
List Images | docker image ls | |
List Images | docker images | |
List Volumes | docker volume ls | |
Publish Image | docker push yourusername/image-name | |
Remove Containers | docker container prune | Delete all stopped/exited containers. |
Remove Containers | docker container prune | Remove all stopped containers. |
Remove Containers | docker container rm container-name-or-id | |
Remove Containers | docker rm $(docker ps -a -q -f status=exited) | Delete all containers with status "exited". |
Remove Image | docker image rm image-id | |
Remove Unused Volumes | docker volume prune | Remove all unused local volumes. |
Remove Volume | docker volume rm volume-id | |
Restart Container | docker restart container-name-or-id | |
Run Image | docker run image-name | Create and run a new container from an image. |
Run Image Detach/Expose Ports | docker run -d -P image-name | Create and run a new container from an image detached and publish all exposed ports to random ports. |
Run Image Interactive | docker run image-name -it /bin/bash | Create and run a new container from an image and connect using BASH. |
Run Image Specific Port | docker run -p 8888:80 image-name | Create and run a new container from an image on ports 8888:80. |
Run Image Then Remove | docker run -rm image-name | Create and run a new container from image, after exited delete container. |
Run Shell Command | docker container exec -it container-name-or-id ls /var | The command will be executed within the shell container. |
Show Container Details | docker container inspect container-name-or-id | Display detailed information on one or more containers. |
Show Container Logs | docker logs container-name-or-id | |
Show Container Processes | docker top container-name-or-id | |
Show Container Stats | docker stats container-name-or-id | |
Start Container | docker start container-name-or-id | |
Start Shell Session | docker container exec -it container-name-or-id /bin/bash | |
Stop Container | docker container stop container-name-or-id | |
Stop Container | docker kill container-name-or-id | Force stop a running container. |
Stop Container | docker stop container-name-or-id |
Notes¶
- To detach from a running container without stopping it, press CTRL-P CTRL-Q
- To detach from a running container by stopping it press CTRL-C