0

In devcontainer.json we have access to these variables:

${localWorkspaceFolder}
${containerWorkspaceFolder}
${localWorkspaceFolderBasename}
${containerWorkspaceFolderBasename}

I have tried making these variables available in .devcontainer.json like this:

{
    "dockerComposeFile": "docker-compose.yml",
    "service": "my-devcontainer",
    "containerEnv": {
          "THING_I_WANT_TO_PASS": "${localWorkspaceFolderBasename}",
      },
      "remoteEnv": {
          "THING_I_WANT_TO_PASS": "${localWorkspaceFolderBasename}",
      },
}

So that they can be used in my docker-compose.yml like so:

services:
  my-devcontainer:
    container_name: "${THING_I_WANT_TO_PASS}-just-example"

But I still get this error VsCode attempts to build the container:

level=warning msg="The "THING_I_WANT_TO_PASS" variable is not set. Defaulting to a blank string.

1 Answer 1

0

It's not great, but you can create an .env file during initializeCommand that will be used by docker-compose.yml.

In .devcontainer.json:

{
    "dockerComposeFile": "docker-compose.yml",
    "service": "my-devcontainer",
    "initializeCommand": "echo THING_I_WANT_TO_PASS=${localWorkspaceFolderBasename} > .devcontainer/.env"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.