Docker Command Line Interface

๐Ÿณ Docker CLI Cheat Sheet

Your one-stop guide to mastering Docker commands ๐Ÿš€

๐Ÿ“ฆ SECTION 1: Image Commands

Command
Description
Example

docker pull <image>
โฌ‡๏ธ Pull an image from Docker Hub
docker pull ubuntu

docker …


This content originally appeared on DEV Community and was authored by Darshan Vasani

๐Ÿณ Docker CLI Cheat Sheet

Your one-stop guide to mastering Docker commands ๐Ÿš€

๐Ÿ“ฆ SECTION 1: Image Commands

Command Description Example
docker pull <image> โฌ‡๏ธ Pull an image from Docker Hub docker pull ubuntu
docker images ๐Ÿ“ธ List all local images docker images
docker rmi <image> ๐Ÿ—‘๏ธ Remove an image docker rmi ubuntu
docker tag <img> <repo>:<tag> ๐Ÿท๏ธ Tag image for push or rename docker tag myimg myrepo:v1
docker build -t <tag> . ๐Ÿ—๏ธ Build image from Dockerfile docker build -t myapp .

๐Ÿณ SECTION 2: Container Lifecycle

Command Description Example
docker run <image> ๐Ÿš€ Run a container docker run ubuntu
docker run -it <image> ๐Ÿ–ฅ๏ธ Interactive container with terminal docker run -it ubuntu bash
docker run -d <image> ๐Ÿ”„ Run in background (detached mode) docker run -d nginx
docker ps ๐Ÿ“‹ List running containers docker ps
docker ps -a ๐Ÿ“‹ List all containers (including stopped) docker ps -a
docker stop <id> ๐Ÿ›‘ Stop a running container docker stop 123abc
docker start <id> โ–ถ๏ธ Start a stopped container docker start 123abc
docker restart <id> ๐Ÿ” Restart a container docker restart 123abc
docker rm <id> โŒ Remove a container docker rm 123abc
docker logs <id> ๐Ÿ“œ View container logs docker logs 123abc

๐Ÿ“‚ SECTION 3: Volume and Data Management

Command Description Example
docker volume create <name> ๐Ÿ—ƒ๏ธ Create a volume docker volume create myvol
docker volume ls ๐Ÿ“‹ List volumes docker volume ls
docker volume rm <name> ๐Ÿงน Delete a volume docker volume rm myvol
-v host:container ๐Ÿ”— Mount volume inside container docker run -v $(pwd):/app ubuntu

๐ŸŒ SECTION 4: Networking

Command Description Example
docker network ls ๐ŸŒ List networks docker network ls
docker network create <name> ๐Ÿ› ๏ธ Create a custom network docker network create mynet
docker network connect <net> <container> ๐Ÿ”Œ Connect a container to a network docker network connect mynet webapp
-p host:container ๐ŸŒ Publish port to host docker run -p 8080:80 nginx

๐Ÿงช SECTION 5: Exec & Inspect

Command Description Example
docker exec -it <id> bash ๐Ÿ› ๏ธ Run command inside running container docker exec -it web bash
docker inspect <id> ๐Ÿ” Detailed info on container/image docker inspect 123abc
docker stats ๐Ÿ“ˆ Real-time usage (CPU, MEM) docker stats
docker top <id> ๐Ÿ‘จโ€๐Ÿ’ป Show running processes inside container docker top web

๐Ÿ”„ SECTION 6: Save, Load, and Export

Command Description Example
docker save -o <file>.tar <img> ๐Ÿ’พ Save image to .tar file docker save -o ubuntu.tar ubuntu
docker load -i <file>.tar ๐Ÿ“ค Load image from tar file docker load -i ubuntu.tar
docker export <id> > file.tar ๐Ÿ“ฆ Export container filesystem docker export 123abc > ubuntu.tar
docker import <file> ๐Ÿ” Import tar as image docker import ubuntu.tar

โ˜๏ธ SECTION 7: DockerHub Login & Push

Command Description Example
docker login ๐Ÿ” Login to DockerHub docker login
docker logout ๐Ÿ”“ Logout from DockerHub docker logout
docker push <user>/<image> ๐Ÿ“ค Push image to DockerHub docker push myuser/myapp

๐Ÿ“„ SECTION 8: Dockerfile Related

Command Description Example
FROM ๐Ÿ“ฆ Base image FROM node:18
COPY ๐Ÿ“ Copy files COPY . /app
RUN ๐Ÿ”ง Execute command in build RUN npm install
CMD ๐Ÿš€ Default container command CMD ["node", "app.js"]
EXPOSE ๐ŸŒ Document exposed port EXPOSE 3000

๐Ÿšฎ SECTION 9: Clean Up Docker

Command Description Example
docker system prune ๐Ÿงน Remove all unused containers/images/volumes docker system prune
docker image prune ๐Ÿ–ผ๏ธ Remove dangling images docker image prune
docker container prune ๐Ÿ—‘๏ธ Remove stopped containers docker container prune
docker volume prune ๐Ÿ’พ Remove unused volumes docker volume prune

๐Ÿง  Quick Tips

  • Use --rm to auto-remove container on exit:
  docker run --rm ubuntu
  • Run detached with name and port:
  docker run -d --name web -p 80:80 nginx
  • Access logs live:
  docker logs -f <container_id>

๐Ÿณ Docker CLI Mastery with --help

โ€œLearn how to teach yourself every command with confidence.โ€

๐Ÿ” 1. Understanding docker --help

Start with:

docker --help

๐Ÿ‘‰ Shows all major command groups like:

Commands:
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  container   Manage containers
  image       Manage images
  volume      Manage volumes
  network     Manage networks
  ...

๐Ÿง  2. Drill Down into Subcommands with --help

You can add --help to any subcommand to discover available options.

Examples:

What to Explore Command
See all image-related commands docker image --help
See all container commands docker container --help
See all run options docker run --help
See help for specific action docker container start --help

๐Ÿ“š 3. Section-Wise Docker Command Reference

Letโ€™s now organize all commands by category โ€” and how to learn more using --help.

๐Ÿ“ฆ A. Docker Image Commands

Command Description Help Command
docker image ls List images docker image ls --help
docker image pull Pull image from registry docker image pull --help
docker image rm Remove image docker image rm --help
docker image build Build image from Dockerfile docker image build --help
docker image tag Tag image docker image tag --help
docker image inspect Inspect image metadata docker image inspect --help
docker image prune Remove unused images docker image prune --help

๐Ÿ” Explore: docker image --help

๐Ÿณ B. Docker Container Commands

Command Description Help Command
docker container ls List containers docker container ls --help
docker container run Create & start new container docker run --help
docker container start/stop Start/Stop container docker container start --help
docker container exec Execute inside running container docker exec --help
docker container logs Show logs docker logs --help
docker container rm Remove container docker container rm --help
docker container inspect Inspect container info docker container inspect --help
docker container prune Remove all stopped containers docker container prune --help

๐Ÿ” Explore: docker container --help

๐Ÿ“‚ C. Docker Volume Commands

Command Description Help Command
docker volume create Create volume docker volume create --help
docker volume ls List volumes docker volume ls --help
docker volume inspect Inspect volume docker volume inspect --help
docker volume rm Remove volume docker volume rm --help
docker volume prune Delete unused volumes docker volume prune --help

๐Ÿ” Explore: docker volume --help

๐ŸŒ D. Docker Network Commands

Command Description Help Command
docker network create Create a custom network docker network create --help
docker network ls List all networks docker network ls --help
docker network connect Connect container to network docker network connect --help
docker network inspect Network details docker network inspect --help
docker network rm Remove network docker network rm --help

๐Ÿ” Explore: docker network --help

๐Ÿ”„ E. Docker System Cleanup

Command Description Help Command
docker system df Show disk usage docker system df --help
docker system prune Remove unused data docker system prune --help
docker image/container/volume prune Cleanup individual resources Add --help accordingly

๐Ÿ” Explore: docker system --help

โ˜๏ธ F. Docker Registry (DockerHub)

Command Description Help Command
docker login Login to DockerHub docker login --help
docker logout Logout docker logout --help
docker push Push image to registry docker push --help
docker pull Pull image from registry docker pull --help

๐Ÿงช G. Docker Exec/Inspect/Debug

Command Description Help Command
docker exec Run inside container docker exec --help
docker logs Show logs docker logs --help
docker inspect Deep object metadata docker inspect --help
docker stats Real-time resource usage docker stats --help
docker top Processes inside container docker top --help

๐Ÿงฑ H. Docker Build Context

Command Description Help Command
docker build Build image from Dockerfile docker build --help
docker commit Create image from container state docker commit --help
docker history Layer history of image docker history --help

๐Ÿ’ก BONUS: Global Docker Options (docker --help)

At the very top level, Docker offers global flags too:

Option Description
--config Use custom Docker config path
--context Use a specific context
--debug Enable debug mode
--version Show Docker version
--help Show help for any command

๐Ÿ“ฆ Final Tip: Combine Flags for Mastery

Example of full command:

docker run -it --rm -v $(pwd):/app -p 3000:3000 --name myapp node bash

๐Ÿณ Docker CLI Cheat Sheet

Your one-stop guide to mastering Docker commands ๐Ÿš€

๐Ÿ“ฆ SECTION 1: Image Commands

Command Description Example
docker pull <image> โฌ‡๏ธ Pull an image from Docker Hub docker pull ubuntu
docker images ๐Ÿ“ธ List all local images docker images
docker rmi <image> ๐Ÿ—‘๏ธ Remove an image docker rmi ubuntu
docker tag <img> <repo>:<tag> ๐Ÿท๏ธ Tag image for push or rename docker tag myimg myrepo:v1
docker build -t <tag> . ๐Ÿ—๏ธ Build image from Dockerfile docker build -t myapp .

๐Ÿณ SECTION 2: Container Lifecycle

Command Description Example
docker run <image> ๐Ÿš€ Run a container docker run ubuntu
docker run -it <image> ๐Ÿ–ฅ๏ธ Interactive container with terminal docker run -it ubuntu bash
docker run -d <image> ๐Ÿ”„ Run in background (detached mode) docker run -d nginx
docker ps ๐Ÿ“‹ List running containers docker ps
docker ps -a ๐Ÿ“‹ List all containers (including stopped) docker ps -a
docker stop <id> ๐Ÿ›‘ Stop a running container docker stop 123abc
docker start <id> โ–ถ๏ธ Start a stopped container docker start 123abc
docker restart <id> ๐Ÿ” Restart a container docker restart 123abc
docker rm <id> โŒ Remove a container docker rm 123abc
docker logs <id> ๐Ÿ“œ View container logs docker logs 123abc

๐Ÿ“‚ SECTION 3: Volume and Data Management

Command Description Example
docker volume create <name> ๐Ÿ—ƒ๏ธ Create a volume docker volume create myvol
docker volume ls ๐Ÿ“‹ List volumes docker volume ls
docker volume rm <name> ๐Ÿงน Delete a volume docker volume rm myvol
-v host:container ๐Ÿ”— Mount volume inside container docker run -v $(pwd):/app ubuntu

๐ŸŒ SECTION 4: Networking

Command Description Example
docker network ls ๐ŸŒ List networks docker network ls
docker network create <name> ๐Ÿ› ๏ธ Create a custom network docker network create mynet
docker network connect <net> <container> ๐Ÿ”Œ Connect a container to a network docker network connect mynet webapp
-p host:container ๐ŸŒ Publish port to host docker run -p 8080:80 nginx

๐Ÿงช SECTION 5: Exec & Inspect

Command Description Example
docker exec -it <id> bash ๐Ÿ› ๏ธ Run command inside running container docker exec -it web bash
docker inspect <id> ๐Ÿ” Detailed info on container/image docker inspect 123abc
docker stats ๐Ÿ“ˆ Real-time usage (CPU, MEM) docker stats
docker top <id> ๐Ÿ‘จโ€๐Ÿ’ป Show running processes inside container docker top web

๐Ÿ”„ SECTION 6: Save, Load, and Export

Command Description Example
docker save -o <file>.tar <img> ๐Ÿ’พ Save image to .tar file docker save -o ubuntu.tar ubuntu
docker load -i <file>.tar ๐Ÿ“ค Load image from tar file docker load -i ubuntu.tar
docker export <id> > file.tar ๐Ÿ“ฆ Export container filesystem docker export 123abc > ubuntu.tar
docker import <file> ๐Ÿ” Import tar as image docker import ubuntu.tar

โ˜๏ธ SECTION 7: DockerHub Login & Push

Command Description Example
docker login ๐Ÿ” Login to DockerHub docker login
docker logout ๐Ÿ”“ Logout from DockerHub docker logout
docker push <user>/<image> ๐Ÿ“ค Push image to DockerHub docker push myuser/myapp

๐Ÿ“„ SECTION 8: Dockerfile Related

Command Description Example
FROM ๐Ÿ“ฆ Base image FROM node:18
COPY ๐Ÿ“ Copy files COPY . /app
RUN ๐Ÿ”ง Execute command in build RUN npm install
CMD ๐Ÿš€ Default container command CMD ["node", "app.js"]
EXPOSE ๐ŸŒ Document exposed port EXPOSE 3000

๐Ÿšฎ SECTION 9: Clean Up Docker

Command Description Example
docker system prune ๐Ÿงน Remove all unused containers/images/volumes docker system prune
docker image prune ๐Ÿ–ผ๏ธ Remove dangling images docker image prune
docker container prune ๐Ÿ—‘๏ธ Remove stopped containers docker container prune
docker volume prune ๐Ÿ’พ Remove unused volumes docker volume prune

๐Ÿง  Quick Tips

  • Use --rm to auto-remove container on exit:
  docker run --rm ubuntu
  • Run detached with name and port:
  docker run -d --name web -p 80:80 nginx
  • Access logs live:
  docker logs -f <container_id>

๐Ÿณ Docker CLI Mastery with --help

โ€œLearn how to teach yourself every command with confidence.โ€

๐Ÿ” 1. Understanding docker --help

Start with:

docker --help

๐Ÿ‘‰ Shows all major command groups like:

Commands:
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  container   Manage containers
  image       Manage images
  volume      Manage volumes
  network     Manage networks
  ...

๐Ÿง  2. Drill Down into Subcommands with --help

You can add --help to any subcommand to discover available options.

Examples:

What to Explore Command
See all image-related commands docker image --help
See all container commands docker container --help
See all run options docker run --help
See help for specific action docker container start --help

๐Ÿ“š 3. Section-Wise Docker Command Reference

Letโ€™s now organize all commands by category โ€” and how to learn more using --help.

๐Ÿ“ฆ A. Docker Image Commands

Command Description Help Command
docker image ls List images docker image ls --help
docker image pull Pull image from registry docker image pull --help
docker image rm Remove image docker image rm --help
docker image build Build image from Dockerfile docker image build --help
docker image tag Tag image docker image tag --help
docker image inspect Inspect image metadata docker image inspect --help
docker image prune Remove unused images docker image prune --help

๐Ÿ” Explore: docker image --help

๐Ÿณ B. Docker Container Commands

Command Description Help Command
docker container ls List containers docker container ls --help
docker container run Create & start new container docker run --help
docker container start/stop Start/Stop container docker container start --help
docker container exec Execute inside running container docker exec --help
docker container logs Show logs docker logs --help
docker container rm Remove container docker container rm --help
docker container inspect Inspect container info docker container inspect --help
docker container prune Remove all stopped containers docker container prune --help

๐Ÿ” Explore: docker container --help

๐Ÿ“‚ C. Docker Volume Commands

Command Description Help Command
docker volume create Create volume docker volume create --help
docker volume ls List volumes docker volume ls --help
docker volume inspect Inspect volume docker volume inspect --help
docker volume rm Remove volume docker volume rm --help
docker volume prune Delete unused volumes docker volume prune --help

๐Ÿ” Explore: docker volume --help

๐ŸŒ D. Docker Network Commands

Command Description Help Command
docker network create Create a custom network docker network create --help
docker network ls List all networks docker network ls --help
docker network connect Connect container to network docker network connect --help
docker network inspect Network details docker network inspect --help
docker network rm Remove network docker network rm --help

๐Ÿ” Explore: docker network --help

๐Ÿ”„ E. Docker System Cleanup

Command Description Help Command
docker system df Show disk usage docker system df --help
docker system prune Remove unused data docker system prune --help
docker image/container/volume prune Cleanup individual resources Add --help accordingly

๐Ÿ” Explore: docker system --help

โ˜๏ธ F. Docker Registry (DockerHub)

Command Description Help Command
docker login Login to DockerHub docker login --help
docker logout Logout docker logout --help
docker push Push image to registry docker push --help
docker pull Pull image from registry docker pull --help

๐Ÿงช G. Docker Exec/Inspect/Debug

Command Description Help Command
docker exec Run inside container docker exec --help
docker logs Show logs docker logs --help
docker inspect Deep object metadata docker inspect --help
docker stats Real-time resource usage docker stats --help
docker top Processes inside container docker top --help

๐Ÿงฑ H. Docker Build Context

Command Description Help Command
docker build Build image from Dockerfile docker build --help
docker commit Create image from container state docker commit --help
docker history Layer history of image docker history --help

๐Ÿ’ก BONUS: Global Docker Options (docker --help)

At the very top level, Docker offers global flags too:

Option Description
--config Use custom Docker config path
--context Use a specific context
--debug Enable debug mode
--version Show Docker version
--help Show help for any command

๐Ÿ“ฆ Final Tip: Combine Flags for Mastery

Example of full command:

docker run -it --rm -v $(pwd):/app -p 3000:3000 --name myapp node bash


This content originally appeared on DEV Community and was authored by Darshan Vasani


Print Share Comment Cite Upload Translate Updates
APA

Darshan Vasani | Sciencx (2025-07-03T09:33:39+00:00) Docker Command Line Interface. Retrieved from https://www.scien.cx/2025/07/03/docker-command-line-interface/

MLA
" » Docker Command Line Interface." Darshan Vasani | Sciencx - Thursday July 3, 2025, https://www.scien.cx/2025/07/03/docker-command-line-interface/
HARVARD
Darshan Vasani | Sciencx Thursday July 3, 2025 » Docker Command Line Interface., viewed ,<https://www.scien.cx/2025/07/03/docker-command-line-interface/>
VANCOUVER
Darshan Vasani | Sciencx - » Docker Command Line Interface. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/03/docker-command-line-interface/
CHICAGO
" » Docker Command Line Interface." Darshan Vasani | Sciencx - Accessed . https://www.scien.cx/2025/07/03/docker-command-line-interface/
IEEE
" » Docker Command Line Interface." Darshan Vasani | Sciencx [Online]. Available: https://www.scien.cx/2025/07/03/docker-command-line-interface/. [Accessed: ]
rf:citation
» Docker Command Line Interface | Darshan Vasani | Sciencx | https://www.scien.cx/2025/07/03/docker-command-line-interface/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.