Skip to content

Instantly share code, notes, and snippets.

@DamienDabernat
Last active February 18, 2025 10:00
Show Gist options
  • Save DamienDabernat/2cf91406b445d7c2983344f0c226c72b to your computer and use it in GitHub Desktop.
Save DamienDabernat/2cf91406b445d7c2983344f0c226c72b to your computer and use it in GitHub Desktop.

TP3 Exercice pratique : Nginx et page HTML

  1. Créer un Dockerfile dans un dossier vide, qui se nomme Dockerfile :
    FROM nginx:alpine
    COPY index.html /usr/share/nginx/html
  2. Créer un fichier index.html :
    <html>
    <head><title>Mon super site</title></head>
    <body>
      <h1>Hello Docker!</h1>
      <p>Ma page personnalisée.</p>
    </body>
    </html>

  1. Construire l’image :
    docker build -t webserver-image:v1 .
  2. Lancer le conteneur :
    docker run -d --name mysite -p 80:80 webserver-image:v1
    • Ouvrez votre navigateur à l’adresse http://localhost
    • Vérifiez que la page s’affiche.

  1. Exercice - logs :

    • Tapez docker logs mysite. Que voyez-vous ?
    • Modifiez votre index.html,
    • Créez votre plus beau meme grâce à : Meme Generator - Imgflip
    • Puis insérez-le sur votre page web.
    • Rebuild l’image. Relancez le conteneur.
  2. Exercice - arrêt / suppression :

    • Arrêtez le conteneur : docker stop mysite
    • Supprimez-le : docker rm mysite
    • Rajoutez l’option --rm lors du run pour supprimer automatiquement le conteneur quand il s’arrête.

Mettre en place un registry local

  1. Démarrez un registry :

    docker run -d -p 5000:5000 --name local-registry registry:2
  2. Taguez votre image vers le registry :

    docker tag webserver-image:v1 localhost:5000/webserver-image:v1
  3. Poussez l’image :

    docker push localhost:5000/webserver-image:v1

Tester le pull depuis le registry

  1. Supprimez l’image locale pour simuler un nouveau poste :
docker rmi webserver-image:v1
docker rmi localhost:5000/webserver-image:v1
  1. Déplacez ou supprimez votre Dockerfile et index.html pour prouver qu’ils ne sont plus disponibles en local.
  2. Récupérez l’image depuis votre registry :
docker pull localhost:5000/webserver-image:v1
  1. Lancez à nouveau le conteneur :
docker run -d --name mysite -p 80:80 localhost:5000/webserver-image:v1
- Vérifiez à nouveau que `http://localhost` fonctionne.

Nettoyage final

  1. Arrêtez et supprimez votre conteneur mysite :
docker stop mysite
docker rm mysite
  1. Arrêtez et supprimez le registry local :
docker stop local-registry
docker rm local-registry
  1. Supprimez les images non utilisées :
docker image prune

Conclusion

Dans ce cours, vous avez :

  1. Expérimenté la création et l’exécution d’images Docker via un Dockerfile.
  2. Pratiqué les commandes de base (build, run, logs, ps, stop, rm…) et fait un exercice avec Nginx (cela servira pour l'évaluation).
  3. Utilisé un registry local pour stocker et partager vos images.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment