Docker - Complete Cheat Sheet
Learn how to hack Docker via a complete cheat sheet.
A Docker Cheat Sheet provides a quick reference guide for common Docker commands and concepts.
For newcomers, Docker is a containerization platform that allows you to package and distribute applications along with their dependencies in containers.
Here's a Docker cheat sheet with commonly used commands and concepts:
✅ Docker Commands​
Pull an Image​
Download a Docker image from a registry (e.g., Docker Hub).
$ docker pull image_name:tag
List Images​
View a list of locally available Docker images.
$ docker images
Run a Container​
Start a new container from an image.
$ docker run image_name:tag
- Add
-d
to run in detached mode. - Use
--name
to specify a custom container name. - Use
-p
to map ports (e.g.,-p host_port:container_port
).
List Containers​
View a list of running containers.
$ docker ps
- Add
-a
to see all containers, including stopped ones.
Stop a Container​
Stop a running container gracefully.
$ docker stop container_id
Remove a Container​
Delete a stopped container.
$ docker rm container_id
Remove an Image​
Delete a Docker image.
$ docker rmi image_name:tag
Inspect Container​
View detailed information about a container.
$ docker inspect container_id
✅ Docker Compose​
Docker Compose is a tool for defining and running multi-container Docker applications.
Create and Start Services​
Start containers defined in a docker-compose.yml
file.
$ docker-compose up
- Add
-d
to run in detached mode.
Stop Services​
Stop containers defined in a docker-compose.yml
file.
$ docker-compose down
List Services​
View a list of services defined in the docker-compose.yml
file.
$ docker-compose ps
✅ Docker Volumes​
Docker volumes are used to persist data between container runs.
Create a Volume​
Create a named volume.
$ docker volume create volume_name
List Volumes​
View a list of available volumes.
$ docker volume ls
Attach a Volume to a Container​
Mount a volume to a container.
$ docker run -v volume_name:/container_mount_point image_name
✅ Docker Networks​
Docker networks allow containers to communicate with each other.
Create a Network​
Create a custom network.
$ docker network create network_name
List Networks​
View a list of available networks.
$ docker network ls
Attach a Container to a Network​
Connect a container to a custom network.
$ docker network connect network_name container_name
✅ Dockerfile​
A Dockerfile is a script used to create a Docker image.
Create a Dockerfile​
Create a Dockerfile in your project directory.
# Example Dockerfile
FROM base_image:tag
RUN command_to_run
Build an Image​
Build a Docker image using a Dockerfile.
$ docker build -t image_name:tag .
✅ Additional Docker Commands​
Logs​
View container logs.
$ docker logs container_id
Exec​
Run a command in a running container.
$ docker exec -it container_id command
Prune​
Remove stopped containers, unused networks, and dangling images.
$ docker system prune
Login to a Registry​
Log in to a Docker image registry (e.g., Docker Hub).
$ docker login
✅ Docker Templates​
This section contains a few open-source starters that include production-ready Docker setups:
👉 Django Bootstrap 5 Volt​
Free starter built on top of Bootstrap 5 and Django with Database, DB Tools, OAuth via Github and Docker Support.
👉 Django Modernize​
Open-Source Seed Project crafted on top of Modernize Bootstrap 5 and Django.
The product comes with session-based authentication, DB tools, and Docker support.
✅ In Summary​
This cheat sheet provides a quick reference for common Docker commands and concepts.
Docker has many more features and options, so be sure to consult the official Docker documentation for more detailed information: https://docs.docker.com/
✅ Resources​
- 👉 Access AppSeed for more starters and support
- 👉 Deploy Projects on Aws, Azure and DO via DeployPRO
- 👉 Create landing pages with Simpllo, an open-source site builder
- 👉 Build apps with Django App Generator (free service)