Docker Commands Cheat Sheet
In this post, I’ve compiled a comprehensive list of docker commands that cover basic Docker commands,
Docker Compose, and Docker Registry.
For each command, I have added a brief explanation of its purpose and usage.
Whether you’re managing containers, orchestrating services with
Docker Compose, or working with Docker Registry, this guide will be you a lot.
Basic Docker Commands# Check Docker version 1
docker --version or docker -v
Display system-wide information about Docker Download an image from Docker Hub. 1
docker pull <image_name>
List local Docker images. 1
docker images or docker image ls
List running containers 1
docker ps or docker container ls
List all containers (including stopped ones) 1
docker ps -a or docker container ls -a
Create and start a new container from an image. 1
docker run <options> <image_name>
Docker Container Lifecycle Management Commands# Start a stopped container 1
docker start <container-name/id>
Stop a running container gracefully. 1
docker stop <container-name/id>
Forcefully stop a running container 1
docker kill <container-name/id>
Restart a container 1
docker restart <container-name/id>
Remove a stopped container 1
docker rm <container-name/id>
Docker Volume Management Commands# Create a named volume 1
docker volume create <volume-name>
Mount a volume to a container 1
docker run -v <volume-name>:<container-path>
List volumes Remove a volume 1
docker volume rm <volume-name>
Docker Network Management Commands# Create a user-defined network 1
docker network create <network-name>
List the docker networks. Connect a container to a network, 1
docker network connect <network-name> <container-name/id>
Disconnect a container from a network 1
docker network disconnect <network-name> <container-name/id>
Disconnect a container from a network 1
docker network disconnect <network-name> <container-name/id>
Remove all unused networks (docket network does not take andy disk space) Docker Image Management Commands# Build a Docker image from a Dockerfile 1
docker build -t <image-name> <path-to-Dockerfile>
Remove an image 1
docker rmi <image-name/id>
Remove all unused images Logs and debugging docker commands# View container logs 1
docker logs <container-name/id>
Start an interactive shell in a running container 1
docker exec -it <container-name/id> /bin/bash
Display real-time container resource usage. 1
docker stats <container-name/id>
Cleanup Commands# Remove all stopped containers, unused networks, and images Remove all stopped containers. Remove all unused images Remove all unused volumes Remove all unused networks (docket network does not take andy disk space) Docker Registry/Hub Commands# Log in to a Docker registry. Push an image to a registry. 1
docker push <image-name>
Pull an image from a registry. 1
docker pull <image-name>
Search an image of official registry 1
docker search <search-text>
Logout from a Docker registry Docker Composer Commands# Start services defined in a docker-compose.yaml
file Stop and remove services defined in a docker-compose.yaml
file List services in a docker-compose.yaml
file and their status. View logs for a specific service 1
docker-compose logs <service-name>
Run a command in a running service container 1
docker-compose exec <service-name> <command>
Understanding Docker, Docker commands, Docker Compose commands, and Docker Registry commands
is essential for anyone working with containers.
This post helps you with the knowledge and confidence to tackle Docker related tasks efficiently.