Closed mbontemps closed 1 year ago
Makes sense to me.
:+1:
Nice idea
I'm not sure we should use /opt/secrets.env
as an example in our documentation, given that we discourage people to use build-time args for secrets (the args are included in the history of an image, so would be visible to others)
i'd really love args_file, i kinda expected it to be there - but i am disappoint now i've found it just got proposed
@thaJeztah Is this planned for the next release?
These tokens should however not appear in your docker-compose.yml file
A workaround is to use a .env
file and ENV variables (compose 1.7+ AFAIR)
version: '2'
services:
php:
build:
dockerfile: Dockerfile-7.0-fpm
context: .
args:
- GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
image: local/dmstr/php-yii2
environment:
- GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
@schmunk42 that workaround didn’t work for me.
@yangm97 Did you try with a recent docker-compose version? Can you set build args in docker-compose (without variables)?
docker-compose version 1.9.0, build 2585387
Setting args on docker-compose.yml work fine.
bot:
build:
args:
- LUA=5.2 # this works
- NATIVE=${NATIVE} # these don't
- ROCKS=${ROCKS}
context: .
command: $BOT
depends_on:
- db
- redis
env_file:
- .deps
- .env
environment:
- NATIVE=${NATIVE}
- ROCKS=${ROCKS}
- REDIS_HOST=redis
- DB_HOST=db
privileged: true
restart: always
So far, the only ways I got to read build time arguments from a file were:
These have to be in your .env
file
NATIVE=${NATIVE}
ROCKS=${ROCKS}
Double check it with docker-compose config
These have to be in your
.env
file
I have multiple env files:
env_file:
- .deps
- .env
Do I need to explicitly set these variables on .env
or it should work when I set these using the .deps
file?
My .deps file looks like this:
LUA=5.2
NATIVE="libreadline-dev libssl-dev lua$LUA luarocks liblua$LUA-dev curl libcurl4-gnutls-dev figlet deborphan git make unzip"
ROCKS="luasec luasocket redis-lua lua-term serpent dkjson Lua-cURL lanes luautf8”
Do I need to explicitly set these variables on .env or it should work when I set these using the .deps file?
Yes, it has to be in .env
- which is the default for docker-compose
. I've written about this in the docs for our application framework. I won't recommend using .env
as an application environment file, btw.
It's a bit confusing, because docker-compose
has "hijacked" this filename, when a lot of people were already using it for applications. I'd call it "control-environment" file now.
Any ETA for that?
Add the env_file
already! 4 years have passed since this was first proposed here.
I think it would make perfect sense if docker build
had support for some --args-file
option, and then compose to align with it. As compose offers option to run the build using the plain docker CLI, transposing arg_file option to the CLI would require extra efforts and potential bugs.
Whats the resolution on this?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Is there a label that can be added to this to prevent it from going stale? It's a feature request.
This issue has been automatically marked as not stale anymore due to the recent activity.
So 5.5 years after this issue was opened: any plans to actually implement that?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
⚡⚡ issue: activate! ⚡⚡
This issue has been automatically marked as not stale anymore due to the recent activity.
As noted on https://github.com/docker/compose/issues/2545#issuecomment-543099520, this feature would only make sense if aligned with other docker commands, i.e. if docker build --args-file ..
is a thing, then obviously docker compose should support this as well.
For this reason, I'm closing this issue as "not planned", in a sense "not planned as a standalone docker compose feature" - if docker CLI or buildx evolves to offer this feature, we'll be happy to de the same.
env-file is not aligned enough?
Motivation for this proposal
2163 proposes a new
build:
section in your Compose servicedocker-compose.yml
file but rather in a separate file.Proposal
Introduce a
args_file:
section working the same way thatenv_file:
works - but in the build phase.Proposed documentation
args_file
Add build arguments from a file. Can be a single value or a list.
If you have specified a Compose file with
docker-compose -f FILE
, paths inargs_file
are relative to the directory that file is in.Environment variables specified in
args
override these values.Compose expects each line in an env file to be in
VAR=VAL
format. Lines beginning with#
(i.e. comments) are ignored, as are blank lines.