docker pull ubuntu:jammyjammy: Pulling from library/ubuntu
Digest: sha256:c7eb020043d8fc2ae0793fb35a37bff1cf33f156d4d4b12ccc7f3ef8706c38b1
Status: Image is up to date for ubuntu:jammy
docker.io/library/ubuntu:jammy
Docker & OCI
2026-02-01
Jupyter Kernel: bash
🖥️ Env Ubuntu 24.04.3 LTS / x86_64 • 🐳 Docker Client 29.1.5 / Server 29.1.5 • 🌿 Git Branch @ 7b914bd
Ce support a été généré par Quarto : les cellules sont exécutées par le noyau indiqué lors du rendu.
Certaines parties ont été rédigées avec l’assistance d’un modèle de langage ; le contenu a été relu et validé par l’auteur.
À la fin de ce cours, vous saurez :
Une image suit la spécification OCI (Open Container Initiative).
[[registry/][namespace/]repository[:tag][@digest]].
repository : partie obligatoire qui identifie le dépôt (nom du répertoire).registry : hôte du registre (optionnel); si absent on entend en pratique le registre Docker Hub (docker.io).namespace : segment optionnel pour regrouper les dépôts (sur Docker Hub, l’espace library est implicite pour les images officielles).tag : référence optionnelle lisible (ex. :latest, :1.2.3); si aucun tag n’est fourni, latest est couramment utilisé comme valeur par défaut pour l’usage, mais l’absence de tag signifie que l’image peut aussi être désignée par un digest.digest : identifiant immuable optionnel (forme sha256:<hex>); lorsqu’il est présent (@digest) il prend la priorité sur le tag pour désigner de façon exacte une image. (Les parties entre crochets [] sont optionnelles selon la spécification de référence des images.)➡️ Une image n’est pas un conteneur mais le modèle de fichier utilisé pour en créer un ou plusieurs.
pull commande pour récupérer une image depuis un registry
ubuntu:jammyIMAGE CREATED CREATED BY SIZE COMMENT
c7eb020043d8 2 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 2 weeks ago /bin/sh -c #(nop) ADD file:b499000226bd9a7c5… 85.6MB
<missing> 2 weeks ago /bin/sh -c #(nop) LABEL org.opencontainers.… 0B
<missing> 2 weeks ago /bin/sh -c #(nop) LABEL org.opencontainers.… 0B
<missing> 2 weeks ago /bin/sh -c #(nop) ARG LAUNCHPAD_BUILD_ARCH 0B
<missing> 2 weeks ago /bin/sh -c #(nop) ARG RELEASE 0B
Avantages :
Méthode possible mais déconseillée :
docker commitLancer un conteneur Ubuntu : docker run --name my-ubuntu --interactive ubuntu:jammy bash
Installer Git en interactif : apt-get update && apt-get install -y git
Valider l’image et supprimer le conteneur intermédiaire.
sha256:b2d89165b41699efa2f726735b3d02bff153a97a14e26237ee9bdbe36d524057
my-ubuntu
mygit:latest est créée.mygit.IMAGE CREATED CREATED BY SIZE COMMENT
b2d89165b416 3 seconds ago bash - 156MB
c7eb020043d8 2 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 2 weeks ago /bin/sh -c #(nop) ADD file:b499000226bd9a7c5… 85.6MB
<missing> 2 weeks ago /bin/sh -c #(nop) LABEL org.opencontainers.… 0B
<missing> 2 weeks ago /bin/sh -c #(nop) LABEL org.opencontainers.… 0B
<missing> 2 weeks ago /bin/sh -c #(nop) ARG LAUNCHPAD_BUILD_ARCH 0B
<missing> 2 weeks ago /bin/sh -c #(nop) ARG RELEASE 0B
➡️ Une seule couche opaque ajoutée
Faire l’exercice :
Pratique Container Image — Exercice 1
✅ Cloned new repository: ebpro/notebook-containers-intro-sample-python-helloworld
# syntax=docker/dockerfile:1
# Choose the parent image
FROM python:3.12-slim
# An argument sets at build command with --build-arg
# It as a default value
ARG BUILD_DATE=1970-01-01T00:00:00Z
# key-value pair as image metadata
LABEL maintainer="emmanuel.bruno@univ-tln.fr"
# See http://label-schema.org/rc1/ for a list of usefull labels
LABEL org.label-schema.build-date=$BUILD_DATE
# An environment variable
ENV NAME="John Doe"
# Creates and moves to a directory
WORKDIR /app
# Copy the requirements them in the new image.
# Done before the copy of the src to limit cache invalidations
# when only source code changes.
COPY requirements.txt ./
# Installation of the dependencies
RUN pip install --requirement requirements.txt
# Copy the sources
COPY hello.py ./
# Set the entrypoint for the image (keeps command arguments overrideable)
ENTRYPOINT ["python", "/app/hello.py"]docker image buildsha256:4007cbc112f99c2c400495e28dafdc296fbf9f5810ac91f95d1b9c6215ed7360
ℹ️ Le . est le contexte de build
Bonnes pratiques :
--tag / -t pour nommer l’image1.2.31, 1.2latest[registry/][namespace/]repository:tag
Tag à la construction (--tag / -t) :
docker run-e / --env pour variables d’environnement dans le conteneurFaire l’exercice :
Étapes :
L’instruction HEALTHCHECK permet de définir une commande pour vérifier la santé d’un conteneur en cours d’exécution. Docker exécute périodiquement cette commande et utilise son code de retour pour déterminer l’état du conteneur : 0 (sain), 1 (non sain) ou 2 (réservé).
Exemple :
Options principales :
--interval: fréquence de vérification (ex. 30s).--timeout: délai maximum d’exécution de la commande (ex. 3s).--start-period: délai initial avant la première vérification (ex. 5s).--retries: nombre d’échecs consécutifs avant de considérer le conteneur comme non sain.Les HEALTHCHECK sont utiles pour l’orchestration (restart policies, load balancers) et pour détecter des services défaillants.
Principes essentiels pour réduire la surface d’attaque et rendre les images sûres :
--mount=type=secret) ou des volumes/variables d’environnement au runtime.@sha256:...) ou pinner les versions de paquets pour éviter des mises à jour non contrôlées.apt-get clean && rm -rf /var/lib/apt/lists/*).docker scan, trivy) et générer un SBOM. Ex : trivy image --severity HIGH,CRITICAL myimage:latest.--cap-drop), monter le FS en lecture seule quand possible (--read-only).ENTRYPOINT + CMD = commande complèteCMD absent, arguments passés à docker run sont ajoutés à ENTRYPOINTENTRYPOINT absent, docker run utilise CMD ou les arguments passés| Directive | Rôle |
|---|---|
| ENTRYPOINT | Comportement principal |
| CMD | Paramètres remplaçables |
➡️ Image utilisable comme un programme
Objectifs :
Fonctionnement :
FROM dans un DockerfileCOPY --from=...)✅ Cloned new repository: ebpro/notebook-containers-intro-sample-c
# Build stage
FROM gcc:14-bookworm AS builder
# An argument sets at build command with --build-arg
# It as a default value
ARG BUILD_DATE=1970-01-01T00:00:00Z
# key-value pair as image metadata
LABEL maintainer="emmanuel.bruno@univ-tln.fr"
# See http://label-schema.org/rc1/ for a list of usefull labels
LABEL org.label-schema.build-date=$BUILD_DATE
WORKDIR /src/app
COPY helloworld.c .
RUN gcc -Wall -Wextra -Werror -O2 -fPIE -pie -D_FORTIFY_SOURCE=2 -static-libgcc helloworld.c -o helloworld
# Runtime stage
FROM debian:bookworm-slim
# Create non-root user
RUN groupadd -r appuser && useradd -r -g appuser appuser
WORKDIR /app
# Copy only the compiled binary
COPY --from=builder --chown=appuser:appuser /src/app/helloworld /app/helloworld
# Switch to non-root user
USER appuser
# Set executable permissions
RUN chmod 550 /app/helloworld
ENTRYPOINT ["/app/helloworld"]EXPOSE dans le Dockerfile pour documenter les ports utilisés-p / --publish dans docker run pour mapper les portsDans le Dockerfile :
ℹ️ EXPOSE ne publie pas le port, il documente seulement.
Faire l’exercice :
ENV ni non plus dans ARG (persistants dans l’image)FROM alpine:3.18
# Dépendance nécessaire
RUN apk add --no-cache curl
# ARG pour une valeur non sensible (ex : URL ou nom d'environnement)
ARG API_URL=https://example.com/secure-data
# Utilisation du secret via BuildKit
RUN --mount=type=secret,id=api_key \
curl --max-time 30 -H "Authorization: Bearer $(cat /run/secrets/api_key)" \
${API_URL} -o /tmp/data.json
# On peut ajouter un step pour vérifier que le fichier existe
RUN test -f /tmp/data.json
CMD ["cat", "/tmp/data.json"]docker buildx ou docker build --platformdocker buildx build --push.Dockerfile pour créer des imagesENTRYPOINT définit le comportementCMD fournit des arguments par défautpush Publier sur un registry