Docker quick reference covering container management, images, volumes, networks, Docker Compose, Dockerfile instructions, and debugging techniques.
| Code / Syntax | Description |
|---|---|
docker run -d --name my-app image:tag | Run container in background |
docker run -it image /bin/bash | Run interactive container with shell |
docker run -p 8080:80 image | Map host port 8080 to container port 80 |
docker run -e VAR=value image | Set environment variable |
docker ps | List running containers |
docker ps -a | List all containers (including stopped) |
docker stop container_id | Stop a running container |
docker rm container_id | Remove a stopped container |
docker restart container_id | Restart a container |
docker run --rm image | Auto-remove container when it exits |
docker rename old_name new_name | Rename a container |
| Code / Syntax | Description |
|---|---|
docker build -t name:tag . | Build image from Dockerfile |
docker images | List all local images |
docker pull image:tag | Download image from registry |
docker push user/image:tag | Push image to registry |
docker tag image:v1 image:latest | Tag an image |
docker rmi image_id | Remove an image |
docker image prune -a | Remove all unused images |
docker save image > file.tar | Export image to tar archive |
docker load < file.tar | Import image from tar archive |
docker history image:tag | Show image layer history |
| Code / Syntax | Description |
|---|---|
docker volume create vol_name | Create a named volume |
docker run -v vol_name:/data image | Mount named volume |
docker run -v /host/path:/container/path image | Bind mount host directory |
docker volume ls | List all volumes |
docker volume rm vol_name | Remove a volume |
docker network create my-net | Create a custom network |
docker run --network my-net image | Attach container to network |
docker network ls | List all networks |
docker network inspect my-net | Show network details and connected containers |
docker volume prune | Remove all unused volumes |
| Code / Syntax | Description |
|---|---|
docker compose up -d | Start all services in background |
docker compose down | Stop and remove all services |
docker compose down -v | Stop services and remove volumes |
docker compose build | Build or rebuild all services |
docker compose logs -f service | Follow logs of a service |
docker compose ps | List running compose services |
docker compose exec service sh | Open shell in running service |
docker compose pull | Pull latest images for all services |
docker compose up --scale web=3 | Scale a service to 3 instances |
docker compose config | Validate and print compose config |
| Code / Syntax | Description |
|---|---|
FROM node:20-alpine | Base image |
WORKDIR /app | Set working directory |
COPY package*.json ./ | Copy files into image |
RUN npm install | Run command during build |
EXPOSE 3000 | Document exposed port |
CMD ["node", "server.js"] | Default command to run |
ENTRYPOINT ["python", "app.py"] | Fixed command (args appended) |
ENV NODE_ENV=production | Set environment variable |
ARG VERSION=latest | Build-time variable |
HEALTHCHECK CMD curl -f http://localhost/ || exit 1 | Container health check |
COPY --from=builder /app/dist ./dist | Multi-stage build copy |
| Code / Syntax | Description |
|---|---|
docker logs container_id | View container logs |
docker logs -f --tail 100 container_id | Follow last 100 log lines |
docker exec -it container_id /bin/sh | Open shell in running container |
docker inspect container_id | Show detailed container info (JSON) |
docker stats | Live CPU/memory usage of all containers |
docker top container_id | Show processes running in container |
docker diff container_id | Show filesystem changes in container |
docker cp container_id:/path/file ./local | Copy file from container to host |
docker events | Stream real-time Docker events |
docker system df | Show Docker disk usage summary |
Found this cheat sheet useful? Check out our other references and tools.