Docker cheat sheet with commonly used commands and concepts. 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.
Download a Docker image from a registry (e.g., Docker Hub).
$ docker pull image_name:tag
View a list of locally available Docker images.
$ docker images
Start a new container from an image.
$ docker run image_name:tag
-d
to run in detached mode.--name
to specify a custom container name.-p
to map ports (e.g., -p host_port:container_port
).View a list of running containers.
$ docker ps
-a
to see all containers, including stopped ones.Stop a running container gracefully.
$ docker stop container_id
Delete a stopped container.
$ docker rm container_id
Delete a Docker image.
$ docker rmi image_name:tag
View detailed information about a container.
$ docker inspect container_id
Docker Compose is a tool for defining and running multi-container Docker applications.
Start containers defined in a docker-compose.yml
file.
$ docker-compose up
-d
to run in detached mode.Stop containers defined in a docker-compose.yml
file.
$ docker-compose down
View a list of services defined in the docker-compose.yml
file.
$ docker-compose ps
Docker volumes are used to persist data between container runs.
Create a named volume.
$ docker volume create volume_name
View a list of available volumes.
$ docker volume ls
Mount a volume to a container.
$ docker run -v volume_name:/container_mount_point image_name
Docker networks allow containers to communicate with each other.
Create a custom network.
$ docker network create network_name
View a list of available networks.
$ docker network ls
Connect a container to a custom network.
$ docker network connect network_name container_name
A Dockerfile is a script used to create a Docker image.
Create a Dockerfile in your project directory.
# Example Dockerfile
FROM base_image:tag
RUN command_to_run
Build a Docker image using a Dockerfile.
$ docker build -t image_name:tag .
View container logs.
$ docker logs container_id
Run a command in a running container.
$ docker exec -it container_id command
Remove stopped containers, unused networks, and dangling images.
$ docker system prune
Log in to a Docker image registry (e.g., Docker Hub).
$ docker login
This section contains a few open-source starters that include production-ready Docker setups:
Free starter built on top ofBootstrap 5 and Djangowith Database, DB Tools, OAuth via Github and Docker Support.
Open-Source Seed Project crafted on top of ModernizeBootstrap 5 and Django.
The product comes with session-based authentication, DB tools, and Docker support.
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/