This is how typically a docker-compose.yml file would be structured:
version: "3.7"
services:
serv1:
build: ./serv1
ports:
- 4040:40
env_file:
- ./docker.env
serv2:
build: ./serv2
ports:
- 3000:3000
env_file:
- ./docker.env
serv3:
build: ./serv3
ports:
- 5000:5000
env_file:
- ./docker.env
I have setup some env variables inside a docker.env file which I would like to use and I'm having two questions:
- Trying to use the port on the host, so
serv1:
ports:
- "${SERV1_PORT}:40"
env_file:
- ./docker.env
...
serv2:
ports:
- "${SERV2_PORT}:40"
env_file:
- ./docker.env
but when I build I'm getting the following:
WARN[0000] The "SERV1_PORT" variable is not set. Defaulting to a blank string.
- Instead of including on each service the
env_file:is there a way to specify "globally" the env file on my docker-compose by including it only once? Mean something like this:
services:
serv1: ...
serv2: ...
...
env_file:
- ./docker.env # these variables to be accessible in all