Pass ENV Vars to Docker Containers in Circle 2.0

We’re using Circle 2.0 with docker-compose.

We have ENV vars defined in Circle’s UI. They’re available to the parent Docker container.

However, when running docker-compose up --build -d, the ENV vars are not available to the child Docker containers running on the remote Docker host.

How can we make these ENV vars available?

Pass them to Docker. You can define variables in your compose config.

We’ve currently got a growing list of ENV vars that we’re adding to Circle and our config each time we run into a new one.

Is there anything we can do to automatically pass all Circle ENV vars along to the containers instead of having a huge list of explicitly declared variables in each call to docker-compose?

Right now we’ve got steps with several of these lines, and we’ll likely be adding more as development proceeds:


EDIT: Variables can also be passed with a shorthand of -e SOME_CIRCLE_VAR

Yep. Write a script that lists your env vars available at shell level, and generates a docker-compose shell script as output.

Alternatively, and this might be a bit neater, you could get it to write a YAML file that you provide to your docker-compose up command. It’s not well known that if you provide multiple -f configuration files, they will be read in order and merged, with later ones overriding earlier ones. You can use a (generated) secondary file to inject the variables.

1 Like

env > envfile, cp/mount it to the container, and source that file inside the container.

Thanks for the reply!

We don’t check-in our .env because it contains sensitive data, so this option doesn’t work for us.

The easiest way seems to be manually adding any necessary env vars to compose commands with the -e SOME_CIRCLE_VAR syntax, but if the list will ever get annoyingly long it’s best to write a script to generate the docker-compose commands.

I don’t think that’s what @rohara meant. The command env produces a source file from the environment vars set up from the UI. Using this file, you can use it as a .env directly in DC, or source it as Ryan suggests, inside your container.

1 Like

Good, that’d be awful.

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