Cheatography
https://cheatography.com
Docker Compose for regular use
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Definitions
Image |
A snapshot or blueprint of an environment (OS + app + dependencies) |
Container |
A running instance of an image (lightweight, isolated environment) |
Dockerfile |
A text file with instructions 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 (overridable) |
Context |
Files sent to the Docker engine when building an image |
|
|
docker-compose.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) |
container_name |
Optional name for the container |
ports |
Host-to-container port mapping ("8080:80") |
volumes |
Mount host paths or named volumes ("./data:/app/data") |
environment |
Set environment variables (VAR=value) |
command |
Override CMD from image/Dockerfile |
depends_on |
Declare startup order between services |
networks |
Assign container to network (default if not declared) |
restart |
Auto-restart policy (always, on-failure, unless-stopped) |
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 environment 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-compose up |
Start services (build if needed) |
docker-compose up -d |
Start in background (detached mode) |
docker-compose down |
Stop and remove containers + network |
docker-compose build |
Build services from Dockerfile |
docker-compose ps |
List running services |
docker-compose logs |
View service logs |
docker-compose exec service sh |
Shell into a running container |
docker-compose restart |
Restart all or specific service(s) |
|