Hi everyone!
I’m facing an issue with docker-compose and env_file: directive that is driving me crazy.
I’ve this simple docker-compose.yml file:
version: "3.3"
services:
prometheus:
image: "prom/prometheus:latest"
container_name: "prometheus"
env_file:
- prometheus/conf.d/prometheus.env
command: ["--config.file=/etc/prometheus/prometheus.yml","--storage.tsdb.path=/var/lib/prometheus","--web.console.libraries=/usr/share/prometheus/console_libraries","--web.console.templates=/usr/share/prometheus/consoles","--web.listen-address=${LISTEN_ADDRESS}:${LISTEN_PORT}"]
volumes:
- type: bind
source: prometheus/conf.d/prometheus.yml
target: /etc/prometheus/prometheus.yml
read_only: true
- type: volume
source: prometheus
target: /var/lib/prometheus
network_mode: "host"
My issue here is that if I do:
docker-compose --env-file prometheus/conf.d/prometheus.env -d up prometheus
it works, I get prometheus running and listen on the correct address and port.
however, if I simply do a:
docker-compose up -d prometheus
it just don’t work and log a warning such as:
WARNING: The LISTEN_ADDRESS variable is not set. Defaulting to a blank string.
WARNING: The LISTEN_PORT variable is not set. Defaulting to a blank string.
my issue here is that I don’t get the env_file directive usage, it’s confusing so far because if I do a simple:
docker-compose config
the output is confusing because:
prometheus:
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus
- --web.console.libraries=/usr/share/prometheus/console_libraries
- --web.console.templates=/usr/share/prometheus/consoles
- '--web.listen-address=:'
container_name: prometheus
environment:
LISTEN_ADDRESS: 192.168.1.1
LISTEN_PORT: '9090'
image: prom/prometheus:latest
network_mode: host
volumes:
- read_only: true
source: /home/helyion/services/prometheus/conf.d/prometheus.yml
target: /etc/prometheus/prometheus.yml
type: bind
- source: prometheus
target: /prometheus
type: volume
so environment variables are correctly filled, but the command directive doesn’t use it.
when doing a:
docker-compose --env-file prometheus/conf.d/prometheus.env config
I’ve got this result:
prometheus:
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus
- --web.console.libraries=/usr/share/prometheus/console_libraries
- --web.console.templates=/usr/share/prometheus/consoles
- --web.listen-address=192.168.1.1:9090
container_name: prometheus
environment:
LISTEN_ADDRESS: 192.168.1.1
LISTEN_PORT: '9090'
image: prom/prometheus:latest
network_mode: host
volumes:
- read_only: true
source: /home/helyion/services/prometheus/conf.d/prometheus.yml
target: /etc/prometheus/prometheus.yml
type: bind
- source: prometheus
target: /prometheus
type: volume
so here the command directive is correctly filled and environments are too, I really don’t get it.
for information here is my docker and docker-compose version log:
Docker version 20.10.8, build 3967b7d
docker-compose version 1.29.2, build unknown (pip install)
If anyone can give me an explanation, I’m all in
thanks!