Présentation de Docker
Tim Sangster
Software Engineer @ DataCamp
Téléchargement et décompression d’un fichier en suivant les instructions Docker.
RUN curl http://example.com/example_folder.zip
RUN unzip example_folder.zip
Modifiera le système de fichiers et ajoutera :
/example_folder.zip
/example_folder/
example_file1
example_file2
Ce sont ces modifications qui sont enregistrées dans l'image.
Chaque instruction du fichier Dockerfile est associée aux modifications qu'elle a apportées au système de fichiers de l'image.
FROM docker.io/library/ubuntu
=> Gives us a file system to start from with all files needed to run Ubuntu
COPY /pipeline/ /pipeline/
=> Creates the /pipeline/ folder
=> Copies multiple files in the /pipeline/ folder
RUN apt-get install -y python3
=> Add python3 to /var/lib/
--> Image Docker : Toutes les modifications apportées au système de fichiers par toutes les instructions Dockerfile.
Lors de la création d'un Dockerfile, Docker nous indique sur quelle couche il travaille :
=> [1/3] FROM docker.io/library/ubuntu
=> [2/3] RUN apt-get update
=> [3/3] RUN apt-get install -y python3
Les builds consécutifs sont beaucoup plus rapides, car Docker réutilise les couches qui n'ont pas été modifiées.
Relancer une build :
=> [1/3] FROM docker.io/library/ubuntu
=> CACHED [2/3] RUN apt-get update
=> CACHED [3/3] RUN apt-get install -y python3
Relancer une build avec des modifications :
=> [1/3] FROM docker.io/library/ubuntu
=> CACHED [2/3] RUN apt-get update
=> [3/3] RUN apt-get install -y R
Le fait que les couches soient mises en cache nous aide à comprendre pourquoi, parfois, les images ne changent pas après une rebuild.
=> [1/3] FROM docker.io/library/ubuntu
=> CACHED [2/3] RUN apt-get update
=> CACHED [3/3] RUN apt-get install -y python3
Nous aide à rédiger des fichiers Dockerfile qui s'exécutent plus rapidement, car toutes les couches n'ont pas besoin d'être reconstruites.
Dans le fichier Dockerfile suivant, toutes les instructions doivent être reconstituées si le fichier pipeline.py est modifié :
FROM ubuntu
COPY /app/pipeline.py /app/pipeline.py
RUN apt-get update
RUN apt-get install -y python3
=> [1/4] FROM docker.io/library/ubuntu
=> [2/4] COPY /app/pipeline.py /app/pipeline.py
=> [3/4] RUN apt-get update
=> [4/4] RUN apt-get install -y python3
Nous aide à rédiger des fichiers Dockerfile qui s'exécutent plus rapidement, car toutes les couches n'ont pas besoin d'être reconstruites.
Dans le fichier Dockerfile suivant, seule l'instruction COPY devra être réexécutée.
FROM ubuntu
RUN apt-get update
RUN apt-get install -y python3
COPY /app/pipeline.py /app/pipeline.py
=> [1/4] FROM docker.io/library/ubuntu
=> CACHED [2/4] RUN apt-get update
=> CACHED [3/4] RUN apt-get install -y python3
=> [4/4] COPY /app/pipeline.py /app/pipeline.py
Présentation de Docker