I'm trying to pass an environment variable into docker-compose up
.
The documention mentions docker-compose run -e
. But the FAQ says we should use up
not run
. docker-compose up -e
isn't supported.
@malathi13
Hi @melissachang
I'd need to know more details about what you're trying to achieve, but a -e
option to up
would feed into every service of the stack, which is not a usecase I've seen before. Do you mind explaining why you need this? Typically, let's say you need the FOO value in service1
to change on subsequent up
calls, the following would be the proper approach:
version: '2.4'
services:
service1:
image: alpine:latest
environment:
FOO: ${FOO:-default}
...
$ docker-compose up # FOO in service1 will be "default"
$ FOO=bar docker-compose up # FOO in service1 will be "bar"
$ FOO=1024 docker-compose up # FOO in service1 will be "1024"
etc.
Hi, my use case is, I wanted to set an environment variable for one service in my docker-compose.yml. This particular environment variable setting was a one-off, so I didn't want to add it to my docker-compose.yml. I wanted to set from the command-line, without any changes to docker-compose.yml.
+1
After reading the FAQ my inclination was to use docker-compose up -e KEY=VALUE
.
My usecase is to pass secrets while developing on my workstation
docker-compose up -e DB_PASSWORD=foo -e API_TOKEN=bar --build
version: '2.4'
services:
service1:
image: alpine:latest
environment:
DB_PASSWORD: ${DB_PASSWORD}
TOKEN: ${API_TOKEN}
I appreciate that I can do this:
DB_PASSWORD=foo API_TOKEN=bar docker-compose up --build
but I prefer the former because its format seems more consistent with other docker commands including docker-compose run
and thus feel more intuitive.
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.
This issue has been automatically closed because it had not recent activity during the stale period.
Most helpful comment
+1
After reading the FAQ my inclination was to use
docker-compose up -e KEY=VALUE
.My usecase is to pass secrets while developing on my workstation
docker-compose up -e DB_PASSWORD=foo -e API_TOKEN=bar --build
I appreciate that I can do this:
DB_PASSWORD=foo API_TOKEN=bar docker-compose up --build
but I prefer the former because its format seems more consistent with other docker commands including
docker-compose run
and thus feel more intuitive.