You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by bgloss March 10, 2023
I don't get the environment variables from my project's .env file into the docker-compose.ymlsetup with a pretty default project layout.
I want to have in docker-compose.yml a section to create a Postgres container with setting up the environment one by one: POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB and fill them with variables from the project's .env file. The relevant section in docker-compose.yml is:
I do NOT want to have a copy of my .env file in the .devcontainer/ folder, as it is the case in some of the DevContainer templates. This would work, as in this case docker compose loads it by default. I don't want this organization, as the .env file is also needed by the project's code and expected in the project root.
I also don't want to expose the whole .env-file to my container, which I could do with the env_file option in the docker compose service description.
When building a container myself (just docker, no docker compose), I can add in devcontainer.json the option runArgs next to the option build giving the env-file information to docker: --env-file ../.env However, this is not possible when using a docker-compose setup in vscode and DevContainers with "dockerComposeFile": "docker-compose.yml".
As a developer, I want to point
docker compose
to my (the correct).env
-file.Discussed in https://github.com/orgs/devcontainers/discussions/36
Originally posted by bgloss March 10, 2023
I don't get the environment variables from my project's
.env
file into thedocker-compose.yml
setup with a pretty default project layout.My project layout is as follows:
I want to have in
docker-compose.yml
a section to create a Postgres container with setting up the environment one by one:POSTGRES_USER
,POSTGRES_PASSWORD
, andPOSTGRES_DB
and fill them with variables from the project's.env
file. The relevant section indocker-compose.yml
is:I do NOT want to have a copy of my
.env
file in the.devcontainer/
folder, as it is the case in some of the DevContainer templates. This would work, as in this casedocker compose
loads it by default. I don't want this organization, as the.env
file is also needed by the project's code and expected in the project root.I also don't want to expose the whole
.env
-file to my container, which I could do with theenv_file
option in the docker compose service description.When building a container myself (just
docker
, nodocker compose
), I can add indevcontainer.json
the optionrunArgs
next to the optionbuild
giving the env-file information to docker:--env-file ../.env
However, this is not possible when using a docker-compose setup invscode
andDevContainers
with"dockerComposeFile": "docker-compose.yml"
.https://containers.dev/implementors/json_reference/
At the command line
docker compose --env-file ../.env up
does the trick.So, my questions:
devcontainer.json
?The text was updated successfully, but these errors were encountered: