Gestion des images
Objectifs du chapitre
- Gérer les images locales
- Télécharger depuis des registres
- Construire des images
- Configurer des registres privés
1 - Liste des images
Vue d'ensemble
┌─────────────────────────────────────────────────────────────────┐
│ 🖼️ Images [+ Build] [Pull Image] │
├─────────────────────────────────────────────────────────────────┤
│ □ Repository Tag ID Size │
│ ──────────────────────────────────────────────────────────────│
│ □ nginx alpine a8758716bb6a 40.7 MB │
│ □ nginx latest 3f8a4339aadd 187 MB │
│ □ postgres 15 3db8720ecbf5 412 MB │
│ □ redis 7-alpine 5685937b6bc1 32 MB │
│ □ myapp v1.0 abc123def456 250 MB │
│ □ <none> <none> xyz789... 150 MB │
│ │
│ Total: 6 images (1.1 GB) | Unused: 2 images (300 MB) │
│ │
└──────────────────────────────────────────────────────────────── ─┘
Informations affichées
| Colonne | Description |
|---|---|
| Repository | Nom de l'image |
| Tag | Version |
| ID | Identifiant court |
| Size | Taille sur disque |
| Created | Date de création |
| Used | Si utilisée par un conteneur |
2 - Télécharger une image (Pull)
Interface de pull
┌─────────────────────────────────────────────────────────────────┐
│ Pull Image │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Registry: [Docker Hub ▼] │
│ │
│ Image: [nginx:alpine ] │
│ │
│ ☐ Always pull the latest version │
│ │
│ [Pull the image] │
│ │
└─────────────────────────────────────────────────────────────────┘
Formats supportés
# Image officielle
nginx
# Avec tag
nginx:1.25-alpine
# Depuis Docker Hub
library/nginx:latest
# Depuis un registre privé
registry.example.com/myapp:v1
# Avec digest
nginx@sha256:abc123...
Progression du téléchargement
┌─────────────────────────────────────────────────────────────────┐
│ Pulling nginx:alpine... │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ✅ Layer 1/5: Already exists │
│ ✅ Layer 2/5: Already exists │
│ ⏳ Layer 3/5: Downloading... 15.2 MB / 23.5 MB (65%) │
│ ⏳ Layer 4/5: Waiting... │
│ ⏳ Layer 5/5: Waiting... │
│ │
│ Progress: ████████████████░░░░░░░░░░░░░░ 65% │
│ │
└─────────────────────────────────────────────────────────────────┘
3 - Construire une image (Build)
Interface de build
┌─────────────────────────────────────────────────────────────────┐
│ Build Image │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Method: ( ) Web editor (•) Upload ( ) Git repository │
│ │
│ Name: [myapp ] │
│ Tag: [v1.0 ] │
│ │
│ Dockerfile: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ FROM node:18-alpine │ │
│ │ WORKDIR /app │ │
│ │ COPY package*.json ./ │ │
│ │ RUN npm ci --only=production │ │
│ │ COPY . . │ │
│ │ EXPOSE 3000 │ │
│ │ CMD ["node", "server.js"] │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Additional files: [📁 Upload files...] │
│ │
│ [Build the image] │
│ │
└─────────────────────────────────────────────────────────────────┘
Options de build
| Option | Description |
|---|---|
| Web editor | Écrire le Dockerfile directement |
| Upload | Télécharger un tar avec le contexte |
| Git repository | Cloner depuis Git |
| URL | Télécharger depuis une URL |
Build depuis Git
┌─────────────────────────────────────────────────────────────────┐
│ Build from Git │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Repository URL: [https://github.com/user/repo ] │
│ │
│ Reference: [main ] │
│ │
│ Dockerfile path: [Dockerfile ] │
│ │
│ ☐ Use authentication │
│ │
│ Build args: │
│ [NODE_ENV ] = [production ] [+ Add] │
│ │
└─────────────────────────────────────────────────────────────────┘
4 - Actions sur les images
Menu d'actions
| Action | Description |
|---|---|
| Pull | Re-télécharger (mise à jour) |
| Push | Pousser vers un registre |
| Tag | Ajouter un tag |
| Export | Exporter en tar |
| Remove | Supprimer |
Taguer une image
┌───────────────────────────────────── ────────────────────────────┐
│ Tag Image: nginx (abc123...) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Registry: [registry.example.com ▼] │
│ │
│ Repository: [mycompany/nginx ] │
│ │
│ Tag: [v1.0 ] │
│ │
│ [Tag] │
│ │
└─────────────────────────────────────────────────────────────────┘
Pousser vers un registre
┌─────────────────────────────────────────────────────────────────┐
│ Push Image │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Image: mycompany/nginx:v1.0 │
│ │
│ Registry: registry.example.com │
│ │
│ Pushing... │
│ ✅ Layer 1/4: Pushed │
│ ✅ Layer 2/4: Pushed │
│ ⏳ Layer 3/4: Pushing... 45% │
│ ⏳ Layer 4/4: Waiting │
│ │
└─────────────────────────────────────────────────────────────────┘
5 - Registres Docker
Ajouter un registre
Settings > Registries > + Add registry
┌─────────────────────────────────────────────────────────────────┐
│ Add Registry │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Type: (•) Custom registry │
│ ( ) Docker Hub │
│ ( ) AWS ECR │
│ ( ) Azure Container Registry │
│ ( ) GitLab │
│ ( ) GitHub │
│ ( ) Quay.io │
│ │
│ Name: [My Registry ] │
│ │
│ URL: [registry.example.com ] │
│ │
│ Authentication: │
│ Username: [admin ] │
│ Password: [•••••••••• ] │
│ │
│ [Add registry] │
│ │
└─────────────────────────────────────────────────────────────────┘
Registres supportés
| Type | Configuration |
|---|---|
| Docker Hub | Username + Access Token |
| AWS ECR | Access Key + Secret + Region |
| Azure ACR | URL + Username + Password |
| GitLab | URL + Deploy Token |
| GitHub | ghcr.io + PAT |
| Custom | URL + credentials |
Utiliser un registre
Une fois configuré, le registre apparaît dans :
- Pull image (sélection du registre)
- Push image (destination)
- Build (destination après build)
6 - Nettoyage des images
Images danglings (sans tag)
┌─────────────────────────────────────────────────────────────────┐
│ 🖼️ Images │
├─────────────────────────────────────────────────────────────────┤
│ Show: [All ▼] [Dangling images only] │
│ │
│ □ <none> <none> abc123... 150 MB 2 weeks ago │
│ □ <none> <none> def456... 200 MB 3 weeks ago │
│ □ <none> <none> ghi789... 100 MB 1 month ago │
│ │
│ [Remove selected] [Remove all dangling images] │
│ │
└─────────────────────────────────────────────────────────────────┘
Images non utilisées
┌────────────────────────────── ───────────────────────────────────┐
│ Image Cleanup │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Unused images: 5 (1.2 GB) │
│ │
│ □ nginx:1.23 Not used by any container 187 MB │
│ □ postgres:14 Not used by any container 400 MB │
│ □ redis:6 Not used by any container 32 MB │
│ │
│ ⚠️ Removing unused images will free 1.2 GB │
│ │
│ [Prune unused images] │
│ │
└─────────────────────────────────────────────────────────────────┘
7 - Détails d'une image
Inspection
┌─────────────────────────────────────────────────────────────────┐
│ 🖼️ nginx:alpine │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Details: │
│ ─────────────────────────────────────────────────────────────│
│ ID: sha256:a8758716bb6aa... │
│ Created: 2024-01-10 00:00:00 │
│ Size: 40.7 MB │
│ Architecture: amd64 │
│ OS: linux │
│ │
│ Layers (5): │
│ ─────────────────────────────────────────────────────────────│
│ 1. ADD file:... (3.4 MB) │
│ 2. CMD ["/bin/sh"] │
│ 3. LABEL maintainer=... │
│ 4. RUN /bin/sh -c set -x... │
│ 5. COPY file:... │
│ │
│ Environment: │
│ ───────────────────────────────── ────────────────────────────│
│ PATH=/usr/local/sbin:/usr/local/bin:... │
│ NGINX_VERSION=1.25.3 │
│ │
└─────────────────────────────────────────────────────────────────┘
8 - Bonnes pratiques
Gestion des tags
# ✅ Utiliser des versions spécifiques
nginx:1.25.3-alpine
# ⚠️ Éviter latest en production
nginx:latest
# ✅ Taguer vos images avec des versions
myapp:v1.2.3
myapp:v1.2.3-20240115
Nettoyage régulier
- Supprimer les images danglings régulièrement
- Retirer les anciennes versions inutilisées
- Surveiller l'espace disque via le dashboard
Sécurité
# ✅ Utiliser des registres authentifiés
# ✅ Scanner les images avant déploiement
# ✅ Éviter les images non officielles
# ✅ Garder les images à jour
Résumé
| Action | Comment |
|---|---|
| Lister | Section Images |
| Pull | Pull Image |
| Build | Build Image |
| Tag | Action Tag |
| Push | Action Push |
| Remove | Action Remove |
| Prune | Remove dangling |
Points clés
- Portainer supporte tous les registres majeurs
- Le build supporte Git, upload et web editor
- Les images danglings consomment de l'espace inutilement
- Configurez vos registres dans Settings
Exercices pratiques
- Téléchargez l'image
python:3.11-alpine - Construisez une image simple depuis le web editor
- Configurez un registre Docker Hub
- Nettoyez les images non utilisées