Cheatsheets
Docker
Everyday Docker & Compose commands for containers, images, and cleanup.
31 entries
Containers9
docker run -d -p 8080:80 nginxRun detached, mapping a port
docker run -it ubuntu bashRun interactively with a shell
docker run --rm -v $PWD:/app -w /app node npm ciThrowaway container, mount cwd
docker psList running containers
docker ps -aList all containers (incl. stopped)
docker exec -it <id> shOpen a shell in a running container
docker logs -f --tail 100 <id>Follow the last 100 log lines
docker stop <id> && docker rm <id>Stop and remove a container
docker cp <id>:/path ./localCopy files out of a container
Images7
docker build -t name:tag .Build an image from the Dockerfile
docker build --no-cache .Build without using the cache
docker imagesList local images
docker pull <image>Download an image from a registry
docker tag <src> <target>Add a tag to an image
docker push <image>Upload an image to a registry
docker history <image>Show an image's layer history
Dockerfile5
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
EXPOSE 3000
CMD ["npm", "start"]Minimal Node image (cache deps before source)
FROM x AS buildName a stage for multi-stage builds
COPY --from=build /app/dist ./distCopy artifacts from another stage
ARG VERSION / ENV NODE_ENV=productionBuild-time arg vs runtime env
HEALTHCHECK CMD curl -f localhost/ || exit 1Container health probe
Compose5
docker compose up -dStart services in the background
docker compose down -vStop services and remove volumes
docker compose logs -f <svc>Follow a service's logs
docker compose exec <svc> shShell into a running service
services:
web:
build: .
ports: ["3000:3000"]
depends_on: [db]
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: secretcompose.yaml: web + postgres
System & cleanup5
docker system dfShow Docker disk usage
docker system prune -aRemove unused images, networks, build cache
docker volume pruneRemove unused volumes
docker statsLive resource usage of containers
docker inspect <id>Low-level details as JSON