Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paulmwatson/2c8f9da7729bd25dca1a280202f75248 to your computer and use it in GitHub Desktop.
Save paulmwatson/2c8f9da7729bd25dca1a280202f75248 to your computer and use it in GitHub Desktop.
Pass environment variables from a .env (dotenv) file into your Docker containers using docker-compose and build ARGs.
# .env
ANIMAL=dog
COLOUR=brown
# docker-compose.yml
...
services:
web:
...
build:
context: .
args:
- ANIMAL=$ANIMAL
- COLOUR=$COLOUR
...
# Dockerfile
...
ARG ANIMAL=dog
ARG COLOUR=brown
ENV ANIMAL=$ANIMAL
ENV COLOUR=$COLOUR
...
# container
> printenv
...
ANIMAL=dog
COLOUR=brown
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment