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

Easy Implementation of Dummy Coding/One-Hot Coding in R

Redis Adventures

CS371p Fall 2021: William Kurtz: Final Entry

Golang Tutorial #3 : Work Environment and Terms in Golang

iCode Guru

How to Use The Rule of Three to Ship a Better Product

Scheduling Jobs in Golang

Offensive Security PWK 2020 Update: Should you upgrade?

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

How to generate a JWT signing keys

Git checkout remote branch in one line

Managed File Transfer (MFT) vs. File Transfer Protocol (FTP)

A smooth Angular migration strategy in a chaotic world