Introducción a Docker
Tim Sangster
Software Engineer @ DataCamp
FROM, RUN y COPY interactúan a través del sistema de archivos.
COPY /projects/pipeline_v3/start.sh /app/start.sh
RUN /app/start.sh
Algunas influyen directamente en otras instrucciones:
WORKDIR: Cambia el directorio de trabajo para las siguientes instruccionesUSER: Cambia el usuario para las siguientes instruccionesEmpezar todas las rutas en la raíz del sistema de archivos:
COPY /projects/pipeline_v3/ /app/
Se vuelve engorroso con rutas largas:
COPY /projects/pipeline_v3/ /home/my_user_with_a_long_name/work/projects/app/
Alternativamente, usa WORKDIR:
WORKDIR /home/my_user_with_a_long_name/work/projects/
COPY /projects/pipeline_v3/ app/
En lugar de usar la ruta completa en cada comando:
RUN /home/repl/projects/pipeline/init.sh
RUN /home/repl/projects/pipeline/start.sh
Establece WORKDIR:
WORKDIR /home/repl/projects/pipeline/
RUN ./init.sh
RUN ./start.sh
En lugar de usar la ruta completa:
CMD /home/repl/projects/pipeline/start.sh
Establece WORKDIR:
WORKDIR /home/repl/projects/pipeline/
CMD start.sh
El comando sobrescrito también se ejecutará en WORKDIR:
docker run -it pipeline_image start.sh
$$
Buena práctica
Ubuntu -> root por defecto
FROM ubuntu --> Usuario root por defecto
RUN apt-get update --> Se ejecuta como root
Instrucción USER en Dockerfile:
FROM ubuntu --> Usuario root por defecto
USER repl --> Cambia el usuario a repl
RUN apt-get update --> Se ejecuta como repl
Dockerfile que establece el usuario a repl:
FROM ubuntu --> Usuario root por defecto
USER repl --> Cambia el usuario a repl
RUN apt-get update --> Se ejecuta como repl
También iniciará contenedores con el usuario repl:
docker run -it ubuntu bash
repl@container: whoami
repl
| Uso | Instrucción de Dockerfile |
|---|---|
| Cambiar el directorio de trabajo actual | WORKDIR <path> |
| Cambiar el usuario actual | USER <user-name> |
Introducción a Docker