简体   繁体   中英

Environment variables from env fiile in entrypoint in docker-compose.yml

I would like to use variable from env-file in docker-compose in entry point:

  # environment.env
  HOST=example.com

  # docker-compose.yml
  some_service:
    ...
    env_file: ['environment.env']
    entrypoint: ['myexecutable', '--host', '$HOST']

Is there any way to do that? I found only one solution:

  # docker-compose.yml
  some_service:
    ...
    env_file: ['environment.env']
    entrypoint: sh -c 'myexecutable --host $$HOST'

But it looks violates docker conception "one process per container" (because there will be 2 processes: sh and myexecutable ). And container does not stop normally, I have to kill it with docker kill or docker-compose kill .

If you want to have just a single process you can run sh -c 'exec myexecutable --host ...' so that it will take over as the single process. Although the "one process per container" generally means that you don't run a process supervisor. It's not that uncommon for one process to start others.

To have the command exit properly on SIGTERM you need to setup explicit signal handlers. You can do that with trap in bash, or in the application itself. See also https://docs.docker.com/compose/faq/#why-do-my-services-take-10-seconds-to-recreate-or-stop

我不确定env文件,但如果它是shell会话中已有的环境变量,则可以在${your_env_var_here} -compose文件中使用${your_env_var_here}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM