简体   繁体   English

来自docker-compose.yml入口点的env fiile的环境变量

[英]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个进程: shmyexecutable )。 And container does not stop normally, I have to kill it with docker kill or docker-compose kill . 并且容器没有正常停止,我必须使用docker killdocker-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.

相关问题 在 docker-compose.yml 的 env_files 中使用系统环境变量 - Use system environment variables in env_files in docker-compose.yml React process.env 无法读取 docker-compose.yml 中的环境变量 - React process.env can't read environment variables in docker-compose.yml 如何在docker-compose.yml的.env文件中使用环境变量? - How do I use environment variables in .env file in docker-compose.yml? 从 .env 或 dockerFile/docker-compose.yml 获取环境变量,到 config,php 以连接到 mysql 数据库 - Get env variables from .env or dockerFile/docker-compose.yml, to config,php to connect to mysql database 如何从.env文件获取环境变量到docker-compose.yml? - How to get the environment variable from .env file on to a docker-compose.yml? 未使用docker-compose.yml在Docker容器中设置环境变量 - Environment variables are not set in docker container using docker-compose.yml 使用 docker-compose.yml 在环境变量定义中插入变量 - Interpolate variables in environment variables definition with docker-compose.yml Docker 从 docker-compose.yml 设置 ENV 变量 - Docker setting an ENV variable from docker-compose.yml 在 docker-compose.yml 中将环境变量从一个服务传递到另一个服务 - Passing env variables from one service to another inside docker-compose.yml 将环境变量从 docker-compose.yml 传递到客户端 Next.js - Passing env variables from docker-compose.yml to the client-side Next.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM