I have two environments development
and production
, I use two files with respective vars of each environment: .env.development
and .env.production
. I'm use, too, docker-compose to load this variables.
COMPOSE_PROJECT_NAME=luna
RAILS_ENV=development
DATABASE_URL=postgresql://user:pass@lunapostgres:5432/luna?encoding=utf8&pool=5&timeout=5000
REDIS_CACHE_URL=redis://:pass@redis:6379/0/cache
ACTIVE_JOB_QUEUE_PREFIX=luna:jobs
ACTIVE_JOB_URL=redis://:pass@redis:6379/0
AUTH_BASE_URL=auth.com
SOLAR_BASE_URL=http://test.url
# SOLAR_BASE_URL=http://api/api/v1/
BUNDLE_PATH=/box
BIND_ON=0.0.0.0:3000
SENTRY_DSN=http://xxxxxxx
PAGER=more
ACCESS_TOKEN=xxx
VERIFY_TOKEN=xxx
DIALOGFLOW_CLIENT_ACCESS_TOKEN=xxx
DIALOGFLOW_DEV_ACCESS_TOKEN=xxx
RAILS_MAX_THREADS=1
WEB_CONCURRENCY=1
REQUEST_TIMEOUT=5
DOMAIN=localhost:3000
BASE_URL=localhost:300
SECRET_TOKEN=xxx
LOG_LEVEL=debug
SOLAR_MENTOS_DEBUG=true
COMPOSE_PROJECT_NAME=luna
RAILS_ENV=production
RACK_ENV=production
DATABASE_URL=postgresql://user:pass@lunapostgres:5432/luna?encoding=utf8&pool=5&timeout=5000
REDIS_CACHE_URL=redis://:pass@redis:6379/0/cache
ACTIVE_JOB_QUEUE_PREFIX=luna:jobs
ACTIVE_JOB_URL=redis://:pass@redis:6379/0
AUTH_BASE_URL=auth.com
SOLAR_BASE_URL=http://test.url
# SOLAR_BASE_URL=http://api/api/v1/
BUNDLE_PATH=/box
BIND_ON=0.0.0.0:3000
SENTRY_DSN=http://xxxxxxx
ACCESS_TOKEN=yyy
APP_SECRET=yyy
VERIFY_TOKEN=yyy
DIALOGFLOW_CLIENT_ACCESS_TOKEN=yyy
DIALOGFLOW_DEV_ACCESS_TOKEN=yyy
RAILS_SERVE_STATIC_FILES=true
RAILS_LOG_TO_STDOUT=true
WEB_CONCURRENCY=5
REQUEST_TIMEOUT=5
RAILS_MAX_THREADS=5
DOMAIN=production.com
BASE_URL=https://production.com
SECRET_TOKEN=yyy
LOG_LEVEL=info
# ----------------------------------------
DEVISE_SECRET_KEY='yyy'
GOOGLE_ANALYTICS_UA='yyy'
version: '2'
services:
app:
env_file:
- '.env.development'
version: '2'
services:
app:
env_file:
- '.env.production'
I would like share equivalents environment variables between my containers, and keep different variables in your respective environment.
Use extendable environment files.
version: '2'
services:
app:
env_file:
- 'base.env'
- 'production.env'
From the Docs
When you set the same environment variable in multiple files, here’s the priority used by Compose to choose which value to use:
- Compose file,
- Environment file
- Dockerfile
- Variable is not defined
The docs are not clear on the use of multiple files so I ran a test. The last environment files overrides previously set variables. If you want to override default values, do so in the last file or in the compose file.
base.env
TEST_VARIABLE=base
production.env
TEST_VARIABLE=production
docker-compose.yml
version: '2.1'
services:
test:
image: alpine
env_file:
- 'base.env'
- 'production.env'
Running docker-compose run --rm test env
gives us TEST_VARIABLE=production
. Thus, the second file overrides the first.
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