Created
August 7, 2020 12:38
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .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