David Armendariz
David Armendariz

Reputation: 1749

Is it possible to have environment and env_file in Docker Compose?

I am new to Gitlab CI/CD and I have the following issue.

Suppose I have some environment variables in my local setup in an .env file. Something like this:

SOME_URL=https://someurl.com/
SECRET_KEY=verysecretkey

For my setup to work, I need both of these environment variables. The SECRET_KEY is not in the .env for the deployment. It is in the "secrets" in GitLab. If I have something like this in my Docker Compose file:

environment:
  SECRET_KEY: ${SECRET_KEY}
env_file:
  - .env

My two questions are:

  1. In my local setup, will I have in my environment variables both SECRET_KEY and SOME_URL?
  2. In GitLab, am I going to be able to replace SECRET_KEY with secrets?

Thanks for your answers in advance!

Upvotes: 1

Views: 587

Answers (1)

Cyril G.
Cyril G.

Reputation: 2017

The variables defined in Gitlab CI/CD are available inside the pipeline (.gitlab-ci.yml). In the step, you are executing the docker-compose command, the variable will be replaced then set in your container thanks to environment: SECRET_KEY: ${SECRET_KEY}. That should be fine.

https://docs.gitlab.com/ee/ci/variables/
https://docs.docker.com/compose/compose-file/#variable-substitution

Upvotes: 1

Related Questions