Show Menu
Cheatography

Docker & Compose Cheat Sheet (DRAFT) by

Docker Compose for regular use

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Defini­tions

Image
A snapshot or blueprint of an enviro­nment (OS + app + depend­encies)
Container
A running instance of an image (light­weight, isolated enviro­nment)
Dockerfile
A text file with instru­ctions to build a Docker image
Volume
Persistent data storage shared between host and container
Bind Mount
Mounts a specific file or folder from host into the container
Port Mapping
Links container port to host port (e.g., -p 8080:80)
Network
Virtual network for containers to talk to each other or the outside world
Base Image
The starting image in a Dockerfile (e.g., FROM ubuntu)
ENTRYPOINT
Default executable when container starts (used for fixed command behavior)
CMD
Arguments passed to ENTRYPOINT or default command (overr­idable)
Context
Files sent to the Docker engine when building an image
 

docker­-co­mpo­se.yml

services
Top-level section; defines each container
image
Use an image from registry or local
build
Build image from Dockerfile (build: . or build: ./app)
contai­ner­_name
Optional name for the container
ports
Host-t­o-c­ont­ainer port mapping ("80­80:­80")
volumes
Mount host paths or named volumes ("./­dat­a:/­app­/da­ta")
enviro­nment
Set enviro­nment variables (VAR=v­alue)
command
Override CMD from image/­Doc­kerfile
depends_on
Declare startup order between services
networks
Assign container to network (default if not declared)
restart
Auto-r­estart policy (always, on-fai­lure, unless­-st­opped)

Dockerfile

FROM
Sets the base image
WORKDIR
Sets working directory inside container
COPY
Copies files into the image
RUN
Executes a command in the image
EXPOSE
Declares which port(s) the container uses
USER
Sets default user inside the container
CMD
Default command to run in a container
ENV
Sets enviro­nment variables
 

Docker commands

docker ps (-a)
List containers
docker exec -it container bash
Run command in a running container (e.g., open shell)
docker stop container
Gracefully stop a container
docker rm container
Delete (remove) a stopped container
docker rmi image
Delete an image
docker logs container
View container output logs

Docker Compose Commands

docker­-co­mpose up
Start services (build if needed)
docker­-co­mpose up -d
Start in background (detached mode)
docker­-co­mpose down
Stop and remove containers + network
docker­-co­mpose build
Build services from Dockerfile
docker­-co­mpose ps
List running services
docker­-co­mpose logs
View service logs
docker­-co­mpose exec service sh
Shell into a running container
docker­-co­mpose restart
Restart all or specific service(s)