Docker CLI Cheat Sheet
The Docker CLI (Command Line Interface) is a powerful tool used to interact with Docker containers, images, networks, and more. This cheat sheet provides a reference for the most commonly used Docker CLI commands.
Commands
Command | Description |
---|---|
docker build -t <image_name> .
|
Build an image from a Dockerfile. |
docker build -t <image_name> . --no-cache
|
Build an image from a Dockerfile without using the cache. |
docker images
|
List all local Docker images. |
docker rmi <image_name>
|
Delete a specific Docker image. |
docker image prune
|
Remove all unused Docker images. |
docker push <username>/<image_name>
|
Publish an image to Docker Hub. |
docker search <image_name>
|
Search Docker Hub for an image. |
docker pull <image_name>
|
Pull an image from Docker Hub. |
Command | Description |
---|---|
docker run --name <container_name> <image_name>
|
Create and run a container with a custom name. |
docker run -p <host_port>:<container_port>
<image_name>
|
Run a container and publish its port(s) to the host. |
docker run -d <image_name>
|
Run a container in the background (detached mode). |
docker start <container_name>
|
Start an existing container. |
docker stop <container_name>
|
Stop a running container. |
docker rm <container_name>
|
Remove a stopped container. |
docker exec -it <container_name> sh
|
Open a shell inside a running container. |
docker logs -f <container_name>
|
Fetch and follow the logs of a container. |
docker inspect <container_name>
|
Inspect a running container. |
docker ps
|
List currently running containers. |
docker ps --all
|
List all Docker containers, both running and stopped. |
docker container stats
|
View resource usage statistics of containers. |
Command | Description |
---|---|
docker login -u <username>
|
Login to Docker Hub with a username. |
docker push <username>/<image_name>
|
Publish an image to Docker Hub. |
docker search <image_name>
|
Search Docker Hub for an image. |
docker pull <image_name>
|
Pull an image from Docker Hub. |
Command | Description |
---|---|
docker --help
|
Get help with Docker commands. You can also use --help with any
subcommand.
|
docker info
|
Display system-wide Docker information. |
docker -d
|
Start the Docker daemon. |
Docker Concepts
Images: Docker images are lightweight, standalone, executable packages that include everything needed to run an application: code, runtime, system tools, system libraries, and settings.
Containers: A container is a runtime instance of a Docker image. Containers isolate software from its environment and ensure that it works uniformly despite differences in infrastructure.
Docker Hub: Docker Hub is a service provided by Docker for finding and sharing container images with your team. Visit Docker Hub to learn more and find images.
Installation: Docker Desktop is available for Mac, Linux, and Windows. Visit Docker Desktop Installation for more information.
Documentation: Check out the official Docker documentation for detailed information on using Docker: Docker Docs.
Example Projects: View example projects that use Docker at Awesome Compose on GitHub.
Additional Information
Command | Description |
---|---|
docker inspect <container_name> | <image_name>
|
Retrieve detailed information about a container or image. |
docker logs <container_name>
|
Fetch the logs of a container. |
docker events
|
Get real-time events from the Docker daemon. |
docker diff <container_name>
|
Inspect changes to files or directories on a container’s filesystem. |
docker top <container_name>
|
Display the running processes of a container. |
Command | Description |
---|---|
docker network ls
|
List all Docker networks. |
docker network create <network_name>
|
Create a new Docker network. |
docker network inspect <network_name>
|
Inspect a Docker network. |
docker network rm <network_name>
|
Remove a Docker network. |
docker network connect <network_name> <container_name>
|
Connect a container to a network. |
docker network disconnect <network_name> <container_name>
|
Disconnect a container from a network. |
Command | Description |
---|---|
docker volume ls
|
List all Docker volumes. |
docker volume create <volume_name>
|
Create a new Docker volume. |
docker volume inspect <volume_name>
|
Inspect a Docker volume. |
docker volume rm <volume_name>
|
Remove a Docker volume. |
docker volume prune
|
Remove all unused Docker volumes. |
Command | Description |
---|---|
docker-compose up
|
Create and start containers defined in a docker-compose.yml file. |
docker-compose down
|
Stop and remove containers, networks, images, and volumes created by docker-compose
up .
|
docker-compose build
|
Build or rebuild services defined in a docker-compose.yml file. |
docker-compose logs
|
View output from containers. |
docker-compose ps
|
List containers. |
docker-compose exec <service> <command>
|
Execute a command in a running service container. |
For more information on Docker Compose, visit the Docker Compose Documentation.