Docker-compose template variables vs environment variables

services:
web:
image: some-image:1.0.0
volumes:
- ${DATA_PATH}:/data
environment:
- NODE_ENV=${NODE_ENV}
restart: unless-stopped
ports:
- 10920:3000
DATA_PATH=/home/data
NODE_ENV=development
$ docker-compose configservices:
web:
environment:
NODE_ENV: development
image: some-image:1.0.0
ports:
- published: 10920
target: 3000
restart: unless-stopped
volumes:
- /home/data:/data:rw
version: '3.9'
docker-compose --env-file dev.env up -d
web:
env_file:
- web-variables.env
web:
environment:
- NODE_ENV=production
docker run --env-file=env_file_name alpine env
  • Calling them as template variables instead of env variables if the purpose of some of these options is for compose file templating makes it more clear.
  • .env files are generally used for maintaining application env variables.Now this combined with compose using .env as the default file for template variables makes it a bit confusing.
  • --env-file cli flag has different behaviour between docker-compose vs docker.docker-compose treats them as template variables and docker injects them as env variables.Of course docker itself has no variable substitution.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Your Guide to Native Apps on AppExchange

This Is How to Declutter Your Brain so You Can Achieve Higher-Level Thinking

2020: The Year of Accessible Data Governance?

How to automatically extract EXIF metadata from photos in Airtable without code

READ/DOWNLOAD@^ Learning RSLogix 5000 Programming:

Tessellation in HDRP

Working with Animation Events in Unity

Introducing WhaleWatch

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
none

none

More from Medium

Getting Started with git

How to merge/squash commits in Git

Gitlab CI automation : Nice things to know before starting!

Backup your database using cron