docker-compose.yaml inside .devcontainer can't access env vars from .env file outside during build #225
Unanswered
Dima-Bulavenko
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
HI, I'm trying to use a
.envfile located outside the.devcontainer/folder to provide build arguments todocker-compose.yamlduring a Dev Container setup.However, since
docker-compose.yamlis placed inside.devcontainer/, it doesn't pick up environment variables from the.envfile in the parent directory during build-time. As a result, theargslike${PYTHON_VERSION}are empty when the image builds.I’d like to avoid duplicating the
.envfile by copying it into.devcontainer/.📁 Folder Structure
📄 .env
📄 .devcontainer/devcontainer.json
{ "dockerComposeFile": "docker-compose.yaml", "service": "development", "workspaceFolder": "/code", // I tried using initializeCommand to load the .env file, // but docker-compose still doesn't see the variables at build-time. "initializeCommand": "export $(grep -v '^#' .env | xargs) && echo ${PYTHON_VERSION}" }📄 .devcontainer/docker-compose.yaml
🧪 Additional Note
When I placed
docker-compose.yamlat the same level as the.envfile, everything worked fine — the variables were picked up during build. But that’s not possible in my case because Dev Containers requiredocker-compose.yamlto be inside.devcontainer/.❓ Question
How can I configure the Dev Container so that:
docker-compose.yaml(inside.devcontainer/) uses a.envfile from the parent folder.envvariables are correctly passed as build-time args.envfile inside.devcontainer/Is there an officially supported way to handle this setup?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions