RousselTMLEARNING

Containers

Docker cheat sheet: the essential commands

A practical guide gathering all the essential commands to handle images, containers, volumes and Docker Compose day to day.

Docker cheat sheet: the essential commands

1. Managing images #

Commands to pull, build and organize your Docker images.

Basic handling #

Images are the templates for your containers. They are immutable.

# Télécharger une image (précisez toujours le tag !)
docker pull nginx:alpine

# Lister les images stockées localement
docker images

# Supprimer une image (rmi = remove image)
docker rmi <image_id_ou_nom>

Building #

The build context is where Docker looks for your files.

# -t : tag (nom:version), le "." est le contexte de build
docker build -t mon-app:1.0 .

# Construire sans utiliser le cache (utile en cas de problème réseau)
docker build --no-cache -t mon-app:1.0 .

2. Container life cycle #

Starting, inspecting and entering your running containers.

Running and state #

A container is a running instance of an image.

# -d : détaché (fond), --name : nommer le conteneur
# -p : mappage port (hôte:conteneur)
docker run -d --name web-srv -p 8080:80 nginx:alpine

# Voir ce qui tourne actuellement
docker ps

# Voir tous les conteneurs, y compris ceux qui ont crashé
docker ps -a

Interaction and debugging #

To troubleshoot, you often need to enter the container or see what it writes.

# -f : suivre les logs (follow)
docker logs -f <container_id>

# -it : mode Interactif avec TTY
docker exec -it <container_name> /bin/sh

docker exec creates a new process in a container that is already running.

3. Volumes and networks #

Managing data persistence and network isolation.

Networks #

Networks let containers communicate with each other by service name.

# Créer un réseau isolé (Bridge par défaut)
docker network create app-net

# Voir quels conteneurs sont sur quel réseau
docker network inspect app-net

Volumes #

Volumes are the only way to keep your data (databases, uploads) after a container is deleted.

# Créer un espace de stockage persistant
docker volume create db-data

# Lister les espaces de stockage
docker volume ls

4. Docker Compose #

Running multi-container applications.

Everyday commands #

Compose automates starting several linked services.

# Lancer toute la stack définie dans docker-compose.yml
docker compose up -d

# Tout arrêter et supprimer les ressources (sauf volumes)
docker compose down

# Voir l'état de santé de la stack
docker compose ps

5. Maintenance and cleanup #

Keeping a clean, efficient system.

Global cleanup #

Be careful: these commands delete unused resources.

# Supprimer conteneurs, réseaux et images non utilisés
docker system prune

# Statistiques de consommation (CPU/RAM)
docker stats

Related articles

Container network security and Kubernetes networking

Secure the container network: how Docker and Kubernetes networking works, CNI, default-deny NetworkPolicies, …

Container registry: choosing and securing your image registry (Docker Hub, Harbor, GHCR, ECR)

Understand container registries: Docker Hub, GitHub Container Registry, cloud registries (ECR, ACR, Artifact …

Docker: overview, architecture and first steps

Discover Docker: containers vs virtual machines, client/daemon/registry architecture, images and layers, esse…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!