¡Esta es una revisión vieja del documento!
Con el comando ARGS puedes definir, dentro del Dockerfile, qué argumentos se pueden usar para construir una imagen:
ARG <name>[=<default value>]
En el siguiente ejemplo se añade un argumento sin valor por defecto user, uno con valor por defecto 3 y luego se usa el argumento con la sintaxis $user.
FROM busybox ARG user ARG buildno=3 USER $user
Como ya sabes el siguiente comando construirá una imagen a partir del Docker file en el directorio actual y la taggeará como automatron. Aún así el . del final no es dónde la genera sino cual es el contexto (el parámetro para indicar el Dockerfile es -f):
docker build -t automatron .
Docker no puede salirse de su contexto para buscar ficheros a la hora de construir una imagen.
$ docker volume create portainer_data $ docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
It’s possible to use environment variables in your shell to populate values inside a Compose file:
web:
image: "webapp:${TAG}"
You can set environment variables with the environment key, just like with docker run -e VARIABLE=VALUE …:
web:
environment:
- DEBUG=1
Pass environment variables to containers without giving a value:
web:
environment:
- DEBUG
You can pass multiple environment variables from an external file with the env_file option, just like with docker run –env-file=FILE …:
web:
env_file:
- web-variables.env
Just like with docker run -e, you can set environment variables with docker-compose run -e:
docker-compose run -e DEBUG=1 web python console.py
You can also pass a variable through from the shell by not giving it a value:
docker-compose run -e DEBUG web python console.py
You can set default values for any environment variables referenced in the Compose file, or used to configure Compose, in an environment file named .env:
$ cat .env
TAG=v1.5
$ cat docker-compose.yml
version: '3'
services:
web:
image: "webapp:${TAG}"