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