Aquesta és una revisió antiga del document
Dockerfile
fichero de scripting para generar un contenedor
FROM debian:latest RUN apt-get update && apt-get install -y wget
docker build -t <nombre> .
: genera una nueva imagen con repositorio <tag>
vagrant rsync
: sincroniza el directorio «compartido» entre el host y la imagen vagrantinstrucciones
- FROM : imagen-plantilla
- ENV : variables de entorno (modificar PATH)
- ARG : variables de Dockerfile (no en el contenedor)
- COPY : copiar ficheros en la imagen
- ADD
- RUN : ejecutar comandos
- VOLUMEN
- EXPOSE
- ENTRYPOINT
- CMD
- USER
- WORKDIR = cd
FROM
imagen de referencia
''FROM <image>'' ''FROM <image:tag>'' ''FROM <@id_imagen>''
RUN
ejecuta comandos en el contenedor (linux)
CMD
CMD [«echo»,«hello world»]
: comando que se ejecuta por defecto
OJO CACHE!
al separar las líneas, el primer RUN es un layer y quedará cacheado (y usado en otras imágenes), lo que hará que nuestro sistema no se actualice. Por eso la línea RUN del update incluye la instalación de soft
FROM debian RUN apt-get update RUN apt-get install -y nginx CMD ["nginx","-g","daemon off;"]
OPTIMIZAR
lo que se tenga que borrar, se tiene que hacer en la misma layer (RUN)
FROM debian RUN apt-get update \ && apt-get install -y nginx \ && rm -rf /var/lib/apt/lists/* CMD ["nginx","-g","daemon off;"]
COPY
COPY file /path/to/file
COPY [–chown=<user||uid>:<group||gid>] file /path/to/file
COPY file file2 file3 /tmp/
COPY fil* /tmp/
COPY . /tmp/
: no usar *
UNION FILE SYSTEM - relación con layers https://en.wikipedia.org/wiki/UnionFS
LAB2
FROM debian:latest RUN apt update && apt install -y nginx CMD ["nginx","-g","daemon off;"] COPY index.html /var/www/html/index.htmlimportante que el COPY esté por debajo del RUN (LAYERS!!!)