Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile environment variables to control CMD arguments #3385

Closed
dsvensson opened this Issue Oct 31, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@dsvensson
Copy link

dsvensson commented Oct 31, 2017

What did you do?

Started prometheus under docker-compose.

What did you expect to see?

Nothing.

What did you see instead? Under which circumstances?

Lots of log INFO's that I want to hide.

Environment

prom/prometheus docker container.

  • System information:

    docker

  • Prometheus version:

    2.0.0-rc2

  • Logs:

prometheus_1  | level=info ts=2017-10-31T22:19:06.761671514Z caller=main.go:215 msg="Starting Prometheus" version="(version=2.0.0-rc.2, branch=master, revision=3701a827cf5da595bd2366dad6e1b3c979a1009c)"

Turns out Prometheus doesn't support adapting command line arguments based on Docker environment variables, which requires copying the whole ENTRYPOINT/CMD from the prom/prometheus Dockerfile:

ENTRYPOINT [ "/bin/prometheus" ]
CMD        [ "--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" ]

...and pasteing into docker-compose.yml, with --log.level=warn added:

    prometheus:
      image: prom/prometheus:master
      entrypoint:
        - "/bin/prometheus"
        - "--log.level=warn"
        - "--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"
      volumes:
        - ./prometheus.yml:/etc/prometheus/prometheus.yml

Ideally this would be possible to either override via Docker environment variables.

Here is how log.level can be overridden for Grafana in docker-compose.yml:

    grafana:
      image: grafana/grafana
      environment:
        GF_LOG_CONSOLE_LEVEL: warn
      depends_on:
        - prometheus
      links:
        - prometheus
      ports:
        - 3000:3000

Maybe something like:

    prometheus:
      image: prom/prometheus:master
      environment:
        PROM_LOG_LEVEL: warn
      volumes:
        - ./prometheus.yml:/etc/prometheus/prometheus.yml

Which would synthesize a --log.level=warn command line argument from a wrapper entrypoint script that traps PROM_ environment variables. This would not require any modifications to Prometheus itself, and would not add any extra way of configuring Prometheus. Just exposing control over the command line to docker-compose.yml.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Nov 1, 2017

Dupe of #3384

@dsvensson

This comment has been minimized.

Copy link
Author

dsvensson commented Nov 1, 2017

@brian-brazil Not duplicate. #3384 was about adding support in Prometheus for reading log.level from config file, in addition to command line argument. As you said, it's better to have one way, and only one way of handling that. This issue was about exposing control over Prometheus startup in docker-compose files by having an entrypoint that builds up the command-line based on docker-compose.yml settings, as Prometheus has an official Docker image at DockerHub. The alternative today is adding the whole command-line to docker-compose.yml which looks kind of dirty as you have to include all command line arguments, even those you don't want to change. Too bad you don't see the value in that, but it is what it is.

@PatrickOsborne

This comment has been minimized.

Copy link

PatrickOsborne commented Feb 28, 2018

I'd like to override the config file used in the image. What would be the best way to do that?

@dbendelman

This comment has been minimized.

Copy link

dbendelman commented May 6, 2018

@dsvensson @PatrickOsborne this might be of interest: #2357 (comment)

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 22, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 22, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.