Docker has become the standard way to package, ship, and run applications. Whether you are deploying microservices, setting up a CI/CD pipeline, or just running a local development environment, these 80+ Docker commands will cover everything you need.
1. Container Lifecycle
docker run -d --name myapp nginx — Run a container in detached mode.
docker run -it ubuntu bash — Run interactively with a shell.
docker run --rm alpine — Run and auto-delete on exit.
docker start myapp — Start a stopped container.
docker stop myapp — Stop a running container gracefully.
docker restart myapp — Restart a container.
docker pause myapp — Pause all processes in a container.
docker unpause myapp — Unpause a container.
docker kill myapp — Force stop a container.
docker rm myapp — Remove a stopped container.
docker rm -f myapp — Force remove a running container.
docker container prune — Remove all stopped containers.
2. Image Management
docker images — List all images.
docker pull nginx — Pull an image from a registry.
docker push myuser/myapp:latest — Push an image to a registry.
docker build -t myapp:1.0 . — Build an image from a Dockerfile.
docker build --no-cache -t myapp . — Build without cache.
docker rmi nginx — Remove an image.
docker rmi $(docker images -q) — Remove all images.
docker image prune — Remove dangling images.
docker image prune -a — Remove all unused images.
docker tag myapp myuser/myapp:latest — Tag an image.
docker save -o myapp.tar myapp:1.0 — Save image to tar file.
docker load -i myapp.tar — Load image from tar file.
docker history myapp:1.0 — Show image layer history.
docker inspect myapp:1.0 — Show detailed image metadata.
3. Inspecting Containers
docker ps — List running containers.
docker ps -a — List all containers (including stopped).
docker logs myapp — View container logs.
docker logs -f myapp — Follow logs in real time.
docker logs --tail 50 myapp — Show last 50 lines.
docker top myapp — Show running processes inside container.
docker stats — Live resource usage for all containers.
docker stats myapp — Resource usage for a specific container.
docker inspect myapp — Detailed container metadata (JSON).
docker inspect -f '{{.NetworkSettings.IPAddress}}' myapp — Get container IP.
docker port myapp — Show port mappings.
docker diff myapp — Show changes to filesystem inside container.
4. Networks
docker network ls — List networks.
docker network create mynet — Create a bridge network.
docker network create --driver overlay mynet — Create an overlay network.
docker run --network=mynet nginx — Run container on a specific network.
docker network connect mynet myapp — Connect running container to network.
docker network disconnect mynet myapp — Disconnect container from network.
docker network inspect mynet — Show network details and connected containers.
docker network prune — Remove unused networks.
5. Volumes and Storage
docker volume ls — List volumes.
docker volume create myvol — Create a volume.
docker run -v myvol:/data nginx — Mount a volume.
docker run -v /host/path:/container/path nginx — Bind mount a host directory.
docker run --mount type=bind,source=/host,target=/container nginx — Bind mount (newer syntax).
docker volume inspect myvol — Show volume details.
docker volume prune — Remove unused volumes.
docker cp myapp:/app/config.json ./config.json — Copy file from container to host.
docker cp ./backup.sql myapp:/backup/ — Copy file from host to container.
6. Docker Compose
docker compose up — Start services defined in compose.yaml.
docker compose up -d — Start in detached mode.
docker compose down — Stop and remove containers, networks.
docker compose down -v — Stop and remove volumes too.
docker compose logs -f — Follow logs from all services.
docker compose ps — List service status.
docker compose build — Build or rebuild images.
docker compose restart — Restart all services.
docker compose exec web bash — Run a command in a running service container.
docker compose run --rm web pytest — Run a one-off command.
docker compose config — Validate and view compose file.
docker compose pull — Pull all service images.
7. Dockerfile Essentials
FROM node:20-alpine — Base image.
WORKDIR /app — Set working directory.
COPY package*.json ./ — Copy files.
RUN npm install — Run build commands.
EXPOSE 3000 — Declare port.
CMD ["node", "server.js"] — Default command.
ENTRYPOINT ["npm", "start"] — Entry point (harder to override).
ENV NODE_ENV=production — Set environment variables.
ARG VERSION=1.0 — Build-time variable.
LABEL maintainer="dev@example.com" — Add metadata.
HEALTHCHECK --interval=30s CMD curl -f http://localhost/ — Health check.
USER node — Switch to non-root user.
VOLUME /data — Create mount point.
ADD app.tar.gz / — Add with auto-extraction (use COPY when possible).
8. Multi-stage Builds
FROM node:20-alpine AS builder — Stage 1 name.
COPY --from=builder /app/dist ./dist — Copy from another stage.
Multi-stage builds keep final images small by discarding build dependencies.
9. Registries and Authentication
docker login — Log in to Docker Hub.
docker login myregistry.com — Log in to a private registry.
docker logout — Log out.
docker search nginx — Search Docker Hub for images.
docker pull myregistry.com/myapp:latest — Pull from private registry.
10. Cleanup and Housekeeping
docker system df — Show disk usage by Docker.
docker system prune — Remove all unused data (containers, images, networks).
docker system prune -a --volumes — Aggressive cleanup (everything unused).
docker container prune — Remove stopped containers.
docker image prune -a — Remove unused images.
docker volume prune — Remove unused volumes.
docker network prune — Remove unused networks.
Also see: Our 100+ Essential Kubernetes Commands guide for container orchestration.
Master Docker and you can deploy anything anywhere. Download our free Docker Commands Cheat Sheet for quick offline reference — 80+ commands in a printable format.
For production deployments, check out the Docker DevOps Toolkit ($15) — 15 Docker resources including compose templates, multi-stage Dockerfiles, CI/CD templates, and cleanup scripts.
Browse our full product catalog for more DevOps tools and cheat sheets.
Also see: Our 100 Essential Linux Commands guide for general server administration.