Hi in docker compose I have:
environment:
- AWS_ACCESS_KEY_ID=$(aws --profile default configure get aws_access_key_id)
- AWS_SECRET_ACCESS_KEY=$(aws --profile default configure get aws_secret_access_key)
But it returns me an error like in topic. Anyone knows how to pass those variables ?
Thanks
For anyone getting this error while trying to pass the DJANGO Secret Key, if your secret key contains '$' add another '$ after it'
DJANGO_SECRET_KEY: "tj...........t2$8" # Original Key
DJANGO_SECRET_KEY: "tj...........t2$$8"
Try with an ENV file.
$ cat ./Docker/api/api.env
NODE_ENV=test
$ cat docker-compose.yml
version: '3'
services:
api:
image: 'node:6-alpine'
env_file:
- ./Docker/api/api.env
environment:
- NODE_ENV=production
You can escape the $ symbol with another $ [like this $$() ] Reference at: https://docs.docker.com/compose/environment-variables/#the-env-file
If the aws command line utility is embedded inside the container then you can rewrite the commands like this.
environment:
- AWS_ACCESS_KEY_ID=$$(aws --profile default configure get aws_access_key_id)
- AWS_SECRET_ACCESS_KEY=$$(aws --profile default configure get aws_secret_access_key)
And if this aws
utility is on the host system then
you can set some environment variables on your shell like (.profile or .bashrc etc)
export HOST_ACCESS_KEY_ID=$(aws --profile default configure get aws_access_key_id)
export HOST_AWS_SECRET_ACCESS_KEY=$(aws --profile default configure get aws_secret_access_key)
and then reuse it in docker-compose.yml like
environment:
- AWS_ACCESS_KEY_ID=${HOST_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${HOST_AWS_SECRET_ACCESS_KEY}
My issue was caused by the fact, that I had been using v2 of docker-file, whereas such an environment option needed to have defined in the header version 3, instead of 2
version: "3"
AFAIK it is not possible to do this in docker-compose
or .env
files. But you can set an environment variable and reference that one in your docker-compose
file:
$ export AWS_ACCESS_KEY_ID=$(aws --profile default configure get aws_access_key_id)
docker-compose.yaml
environment:
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With