tech:docker_image_build
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:docker_image_build [2026/03/03 10:16] – Jean-Baptiste | tech:docker_image_build [2026/08/03 11:19] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | # Docker image build | ||
| + | |||
| + | Voir : | ||
| + | * [Docker Buildx / BuildKit](https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * [[docker_install_dokuwiki|Exemple de Dockerfile pour Dokuwiki]] | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Voir aussi : | ||
| + | * [[Images conteneurs flatten - réduire la taille d'une image]] | ||
| + | |||
| + | |||
| + | Ansible : | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | Outils / Méthode / Container Image Builders : | ||
| + | * Docker / Dockerfile | ||
| + | * Buildah | ||
| + | * Buildpacks / pack https:// | ||
| + | * openshift-imagebuilder | ||
| + | * [Source-To-Image (S2I)](https:// | ||
| + | * Kaniko https:// | ||
| + | * S2I | ||
| + | * CNB | ||
| + | * Paketo | ||
| + | * umoci | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Bonnes pratiques | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Quand cela est possible préférer `COPY` à `ADD`. Voir https:// | ||
| + | |||
| + | Immediately before your ENTRYPOINT or CMD directive, you then add a USER | ||
| + | |||
| + | |||
| + | Ne pas utiliser `sudo` mais `gosu` ou `su-exec` | ||
| + | |||
| + | |||
| + | ### Vérif Dockerfile Conrainerfile avec Hadolint | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | |||
| + | ~~~bash | ||
| + | podman run --rm -i docker.io/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Exemple de Dockerfile et script | ||
| + | |||
| + | https:// | ||
| + | |||
| + | `start.sh` | ||
| + | ~~~bash | ||
| + | #!/bin/bash | ||
| + | set -e | ||
| + | |||
| + | # When docker restarts, this file is still there, | ||
| + | # so we need to kill it just in case | ||
| + | [ -f / | ||
| + | |||
| + | _kill_procs() { | ||
| + | kill -TERM $node | ||
| + | kill -TERM $xvfb | ||
| + | } | ||
| + | |||
| + | # Relay quit commands to processes | ||
| + | trap _kill_procs SIGTERM SIGINT | ||
| + | |||
| + | Xvfb :99 -screen 0 1024x768x16 -nolisten tcp -nolisten unix & | ||
| + | xvfb=$! | ||
| + | |||
| + | export DISPLAY=:99 | ||
| + | |||
| + | dumb-init -- node ./ | ||
| + | node=$! | ||
| + | |||
| + | wait $node | ||
| + | wait $xvfb | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | `Dockerfile` | ||
| + | ~~~ | ||
| + | CMD [" | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Buildah | ||
| + | |||
| + | voir https:// | ||
| + | |||
| + | docker build | ||
| + | |||
| + | ~~~bash | ||
| + | buildah bud -t myapp: | ||
| + | ~~~ | ||
| + | |||
| + | L' | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | `RUN apk add --no-cache shadow` | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | export DOCKER_BUILDKIT=0 | ||
| + | |||
| + | ~~~ | ||
