Introduction à Docker
Tim Sangster
Software Engineer @ DataCamp
FROM, RUN et COPY interagissent via le système de fichiers.
COPY /projects/pipeline_v3/start.sh /app/start.sh
RUN /app/start.sh
Certaines influencent directement les suivantes :
WORKDIR : change le répertoire de travail pour toutes les instructions suivantesUSER : change l'utilisateur pour toutes les instructions suivantesCommencer tous les chemins à la racine du système de fichiers :
COPY /projects/pipeline_v3/ /app/
Devient encombrant avec des chemins longs :
COPY /projects/pipeline_v3/ /home/my_user_with_a_long_name/work/projects/app/
Sinon, utilisez WORKDIR :
WORKDIR /home/my_user_with_a_long_name/work/projects/
COPY /projects/pipeline_v3/ app/
Plutôt que d'utiliser le chemin complet à chaque commande :
RUN /home/repl/projects/pipeline/init.sh
RUN /home/repl/projects/pipeline/start.sh
Définissez WORKDIR :
WORKDIR /home/repl/projects/pipeline/
RUN ./init.sh
RUN ./start.sh
Au lieu d'utiliser le chemin complet :
CMD /home/repl/projects/pipeline/start.sh
Définissez WORKDIR :
WORKDIR /home/repl/projects/pipeline/
CMD start.sh
Une commande de remplacement s'exécutera aussi dans WORKDIR :
docker run -it pipeline_image start.sh
$$
Bonne pratique
Ubuntu -> root par défaut
FROM ubuntu --> Root user by default
RUN apt-get update --> Run as root
Instruction USER dans le Dockerfile :
FROM ubuntu --> Root user by default
USER repl --> Changes the user to repl
RUN apt-get update --> Run as repl
Dockerfile qui définit l'utilisateur sur repl :
FROM ubuntu --> Root user by default
USER repl --> Changes the user to repl
RUN apt-get update --> Run as repl
Démarrera aussi les conteneurs avec l'utilisateur repl :
docker run -it ubuntu bash
repl@container: whoami
repl
| Usage | Instruction Dockerfile |
|---|---|
| Changer le répertoire de travail courant | WORKDIR <path> |
| Changer l'utilisateur courant | USER <user-name> |
Introduction à Docker