Aller au contenu principal

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

ColonneDescription
RepositoryNom de l'image
TagVersion
IDIdentifiant court
SizeTaille sur disque
CreatedDate de création
UsedSi 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

OptionDescription
Web editorÉcrire le Dockerfile directement
UploadTélécharger un tar avec le contexte
Git repositoryCloner depuis Git
URLTé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

ActionDescription
PullRe-télécharger (mise à jour)
PushPousser vers un registre
TagAjouter un tag
ExportExporter en tar
RemoveSupprimer

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

TypeConfiguration
Docker HubUsername + Access Token
AWS ECRAccess Key + Secret + Region
Azure ACRURL + Username + Password
GitLabURL + Deploy Token
GitHubghcr.io + PAT
CustomURL + 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

  1. Supprimer les images danglings régulièrement
  2. Retirer les anciennes versions inutilisées
  3. 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é

ActionComment
ListerSection Images
PullPull Image
BuildBuild Image
TagAction Tag
PushAction Push
RemoveAction Remove
PruneRemove 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

  1. Téléchargez l'image python:3.11-alpine
  2. Construisez une image simple depuis le web editor
  3. Configurez un registre Docker Hub
  4. Nettoyez les images non utilisées

← Gestion des conteneurs | Volumes et réseaux →