Proper way to load ENV from a file when using Docker

docker
2.0

#1

Is there a good way to load ENV vars from a file? For CI and local dev, we commit these to git, as they don’t contain anything private. I would rather read them from here than set them in the docker environment settings like

- image: circleci/python:3.6
    environment:
        REDIS_URL: localhost

It would keep the number of places where configuration resides if I didn’t also have to do it here. Thanks!


#2

Hmm, interesting. You can certainly commit an .env file to your repo, but to use that you’d need to copy it into place first in a run step, and the image you’re referring to will be spun up as a container prior to any of your steps being run.

If this is a primary container, you can of course use source in a run step. However, if it is a secondary container, that’s a bit harder - one solution to that is to abandon multiple containers at the CircleCI level and launch them yourself in Docker Compose.


#3

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.