Skip to content
Docker Cheatsheet — Commands & Quick Reference

Docker Cheatsheet — Commands & Quick Reference

DodaTech 3 min read

Docker CLI commands, Dockerfile syntax, Docker Compose, volumes, networks, and best practices — a dense reference for containerizing and deploying applications.

Docker CLI — Container Lifecycle

CommandWhat it does
docker run -d -p 8080:80 nginxRun container detached, map port
docker run -it ubuntu bashInteractive shell
docker psList running containers
docker ps -aList all containers
docker stop <id>Stop container
docker start <id>Start stopped container
docker rm <id>Remove container
docker rm $(docker ps -aq)Remove all containers

Images

CommandWhat it does
docker imagesList local images
docker pull nginx:alpinePull image from registry
docker rmi <image>Remove image
docker build -t myapp:1.0 .Build image from Dockerfile
docker tag myapp:1.0 user/myapp:1.0Tag image
docker push user/myapp:1.0Push to registry

Exec & Logs

docker exec -it <container> bash    # shell into running container
docker logs -f <container>          # tail logs
docker logs --tail 50 <container>   # last 50 lines

Dockerfile Instructions

InstructionPurpose
FROM python:3.11-slimBase image
WORKDIR /appSet working dir
COPY . .Copy files from context
ADD archive.tar.gz /tmpCopy + auto-extract
RUN pip install -r req.txtExecute command at build
CMD ["python", "app.py"]Default command (runtime)
ENTRYPOINT ["python"]Entry point (runtime)
EXPOSE 8080Document port
ENV MODE=productionSet env variable
ARG VERSION=1.0Build-time variable
VOLUME /dataMount point declaration
USER appuserSwitch user

Example Dockerfile:

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

Docker Compose

# docker-compose.yml
version: "3.9"
services:
  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app
    environment:
      - NODE_ENV=development
  db:
    image: postgres:16
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

Compose commands:

CommandWhat it does
docker compose up -dStart services
docker compose downStop + remove
docker compose logs -fTail logs
docker compose buildRebuild images
docker compose exec web bashShell into service

Volumes & Networks

docker volume create myvol          # create volume
docker volume ls                     # list volumes
docker network create mynet          # create network
docker network ls                    # list networks
# Attach container:
docker run -d --net=mynet --name app myapp

Volume types: bind (host path), volume (managed by Docker), tmpfs (in-memory).

What is the difference between CMD and ENTRYPOINT?
CMD provides defaults for the running container and can be overridden by command-line arguments. ENTRYPOINT sets the main executable that always runs — arguments passed via CLI get appended. They’re often combined: ENTRYPOINT ["python"] + CMD ["app.py"] allows docker run myimage other.py to run other.py instead.
What is the difference between COPY and ADD in a Dockerfile?
COPY copies files from the build context into the image — it’s simple and explicit. ADD does the same but also supports remote URLs and automatic tar extraction. The Docker docs recommend using COPY unless you specifically need ADD’s extra features.
How do I persist data in Docker?
Use volumes (managed by Docker, stored in /var/lib/docker/volumes/) or bind mounts (maps a host directory). Volumes are preferred for production as they’re portable and safer. Declare them with docker volume create or volumes: in Compose.

See the full Docker tutorials for CI/CD and orchestration.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro