Appearance
Docker Cheat Sheet
Container Management
| Command | Description |
|---|---|
docker run [options] IMAGE | Create and start a new container |
docker start CONTAINER | Start a stopped container |
docker stop CONTAINER | Stop a running container |
docker restart CONTAINER | Restart a container |
docker pause CONTAINER | Pause a running container |
docker unpause CONTAINER | Unpause a paused container |
docker rm CONTAINER | Remove a stopped container |
docker exec [options] CONTAINER COMMAND | Run a command in a running container |
docker run options
-d--detach- Run container in background and print container ID-e--env- Set environment variables-i--interactive- Keep STDIN open even if not attached-p--publish- Publish a container's port(s) to the host (format:-p HOST:CONTAINER)-t--tty- Allocate a pseudo-TTY (teletype)-v--volume- Bind mount a volume (format:-v HOST:CONTAINER)
Image Management
| Command | Description |
|---|---|
docker build [options] PATH | Build an image from a Dockerfile |
docker pull IMAGE | Pull an image from a registry |
docker push IMAGE | Push an image to a registry |
docker images | List local images |
docker rmi IMAGE | Remove an image |
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] | Create a tag for an image |
Container Inspection
| Command | Description |
|---|---|
docker ps | List running containers |
docker ps -a | List all containers (including stopped) |
docker logs CONTAINER | View container logs |
docker inspect CONTAINER | Display detailed information about a container |
docker top CONTAINER | Display running processes of a container |
docker stats CONTAINER | Display a live stream of container resource usage statistics |
Image Inspection
| Command | Description |
|---|---|
docker history IMAGE | Show the history of an image |
docker inspect IMAGE | Display detailed information about an image |
Network Management
| Command | Description |
|---|---|
docker network create NETWORK | Create a network |
docker network ls | List networks |
docker network inspect NETWORK | Display detailed information about a network |
docker network connect NETWORK CONTAINER | Connect a container to a network |
docker network disconnect NETWORK CONTAINER | Disconnect a container from a network |
Volume Management
| Command | Description |
|---|---|
docker volume create VOLUME | Create a volume |
docker volume ls | List volumes |
docker volume inspect VOLUME | Display detailed information about a volume |
docker volume rm VOLUME | Remove a volume |
System Management
| Command | Description |
|---|---|
docker info | Display system-wide information |
docker version | Show the Docker version information |
docker system prune | Remove unused data |
docker system df | Show docker disk usage |
Docker Compose
| Command | Description |
|---|---|
docker-compose up | Create and start containers |
docker-compose down | Stop and remove containers, networks, images, and volumes |
docker-compose ps | List containers |
docker-compose logs | View output from containers |
docker-compose build | Build or rebuild services |
Docker Hub
| Command | Description |
|---|---|
docker login | Log in to a Docker registry |
docker logout | Log out from a Docker registry |
docker search TERM | Search Docker Hub for images |
Dockerfile
Base Image & Environment Setup
| Instruction | Description |
|---|---|
FROM <image>:<tag> | Set the base image for subsequent instructions |
ARG <name>[=<default>] | Define a build-time variable |
ENV <key>=<value> | Set an environment variable |
Working Directory
| Instruction | Description |
|---|---|
WORKDIR <path> | Set the working directory for subsequent instructions |
File Manipulation
| Instruction | Description |
|---|---|
COPY <src> <dest> | Copy files or directories from the build context to the container |
ADD <src> <dest> | Copy files or directories from the build context to the container (supports URLs and unpacking archives) |
Running Commands
| Instruction | Description |
|---|---|
RUN <command> | Execute a command in a new layer on top of the current image and commit the results |
Exposing Ports
| Instruction | Description |
|---|---|
EXPOSE <port> | Expose a port to the network |
Volumes
| Instruction | Description |
|---|---|
VOLUME ["/path"] | Create a mount point with the specified name and mark it as holding externally mounted volumes from native host or other containers |
User
| Instruction | Description |
|---|---|
USER <user> | Set the user name or UID to use when running the image |
Labels & Metadata
| Instruction | Description |
|---|---|
LABEL <key>=<value> | Add metadata to an image |
Health Checks
| Instruction | Description |
|---|---|
HEALTHCHECK [options] CMD command | Set a command to run to check the health of a container |
Entrypoint & Runtime Configuration
| Instruction | Description |
|---|---|
ENTRYPOINT ["executable", "param1", "param2"] | Set the primary command to be run when the container starts |
CMD ["executable", "param1", "param2"] | Provide defaults for an executing container |