Présentation de 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 d'autres instructions :
WORKDIR : modifie le répertoire de travail pour toutes les instructions suivantes.USER : modifie l'utilisateur pour toutes les instructions suivantesDémarrage de tous les chemins à la racine root du système de fichiers :
COPY /projects/pipeline_v3/ /app/
Devient encombré lorsque l'on travaille avec des chemins d'accès longs :
COPY /projects/pipeline_v3/ /home/my_user_with_a_long_name/work/projects/app/
Vous pouvez également utiliser WORKDIR :
WORKDIR /home/my_user_with_a_long_name/work/projects/
COPY /projects/pipeline_v3/ app/
Au lieu d'utiliser le chemin complet pour 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
La commande prioritaire sera également exécutée 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 Dockerfile :
FROM ubuntu --> Root user by default
USER repl --> Changes the user to repl
RUN apt-get update --> Run as repl
Dockerfile définissant 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 également les conteneurs avec l'utilisateur repl :
docker run -it ubuntu bash
repl@container: whoami
repl
| Utilisation | Instruction Dockerfile |
|---|---|
| Modifier le répertoire de travail actuel | WORKDIR <path> |
| Modifier l'utilisateur actuel | USER <user-name> |
Présentation de Docker