Docker Cheat Sheet

Images
| Images | Command |
| List available images | docker images [options] |
| Download an image from a registry | docker pull [image_name] |
| Build an image from a Dockerfile | docker build [options] [path_to_dockerfile] |
| Tag an image | docker tag [image_name] [new_image_name] |
| Remove an image | docker rmi [image_name] |
| Remove all unused images | docker image prune |
| Export an image as a tar archive | docker save [image_name] -o [output_file] |
| Import an image from a tar archive | docker load -i [input_file] |
Containers
| Containers | Command |
| Create and start a container | docker run [options] [image_name] [command] |
| Start a stopped container | docker start [container_name] |
| Stop a running container | docker stop [container_name] |
| Remove a stopped container | docker rm [container_name] |
| List running containers | docker ps [options] |
| Create and start a container with an interactive shell | docker run -it [options] [image_name] /bin/bash |
| Create and start a container in detached mode | docker run -d [options] [image_name] [command] |
| Create and start a container with a name | docker run --name [container_name] [options] [image_name] [command] |
| Create and start a container with a specific network | docker run --network [network_name] [options] [image_name] [command] |
| Create and start a container with a specific volume | docker run -v [host_path]:[container_path] [options] [image_name] [command] |
| Create and start a container with environment variables | docker run -e [variable_name]=[variable_value] [options] [image_name] [command] |
Dockerfile
| Dockerfile | Command |
| Set the base image for the Dockerfile | FROM [image_name] |
| Run a command during the image build process | RUN [command] |
| Copy files from the host to the container | COPY [source] [destination] |
| Set the working directory for subsequent commands | WORKDIR [directory_path] |
| Expose a port on the container | EXPOSE [port] |
| Specify the command to be run when the container starts | CMD [command] |
Docker Compose
| Docker Compose | Command |
| Start a stack | docker-compose up [options] |
| Start a stack in detached mode | docker-compose up -d [options] |
| Stop a stack | docker-compose down [options] |
| Restart a service | docker-compose restart [service_name] |
| List running containers for a stack | docker-compose ps |
Volumes
| Volumes | Command |
| Create a named volume | docker volume create [volume_name] |
| List available volumes | docker volume ls |
| Inspect a volume | docker volume inspect [volume_name] |
| Remove a volume | docker volume rm [volume_name] |
| Mount a volume when creating a container | docker run -v [volume_name]:[container_path] [options] [image_name] [command] |
Networks
Create a network |
|
List available networks |
|
Inspect a network |
|
Remove a network |
|
Connect a container to a network |
|
Disconnect a container from a network |
|
Logs & Stats
View container logs |
|
View container logs with timestamps |
|
View container logs in real-time |
|
View container resource usage stats in real-time |
|
View resource usage stats for all running containers |
|
Registries
Upload an image to a registry |
|
Log in to a registry |
|
Log out from a registry |
|

