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 --helpto 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 --helpto 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
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)