[英]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: 我想在入口点使用docker-compose中的env-file变量:
# 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
). 但它看起来违反了docker概念“每个容器一个进程”(因为将有2个进程:
sh
和myexecutable
)。 And container does not stop normally, I have to kill it with docker kill
or docker-compose kill
. 并且容器没有正常停止,我必须使用
docker kill
或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. 如果你想只有一个进程,你可以运行
sh -c 'exec myexecutable --host ...'
以便它将作为单个进程接管。 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. 要在SIGTERM上正确退出命令,您需要设置显式信号处理程序。 You can do that with
trap
in bash, or in the application itself. 您可以使用bash中的
trap
或应用程序本身来实现。 See also https://docs.docker.com/compose/faq/#why-do-my-services-take-10-seconds-to-recreate-or-stop 另请参见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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.