Reputation: 10705
Is there a way to force docker compose to assume environment variables from the underlying machine?
I decided to play around with Docker in my ASP.NET Core Web Application, so I used the Add Docker Support
option in Visual Studio, which created a .dcproj (Docker Compose project).
Prior to that, I was reading some configs from Environment Variables on the current machine (either my dev machine or a server).
I realized when I'm debugging with the docker compose project, I'm not able to get data from Environment Variables anymore, which makes sense, since docker became the new environment (not my machine anymore). I wouldn't like these values to be pushed into my git repo.
Upvotes: 1
Views: 1076
Reputation: 4690
You have to specify the environment variables in the docker-compose.yml
file like this
environment:
- VAR1
- VAR2=fixedvalue
In this case VAR1
assumes the value that is defined for the variable in your computer and VAR2
will assume the value that is specified regardless or what is configured in your computer.
You also have the env_file
option which allows you to specify a file with all the variables set.
env_file:
- web-variables.env
You can find more information in the documentation.
Upvotes: 1