Dev container: where to put environment variables when sourced locally and used in initializeCommand

Hi,

I migrate from VSCode Devcontainer extension. I am starting a devcontainer with that kind of config:

{
  "name": "container_name",
  "dockerComposeFile": [
    "${localWorkspaceFolder}/deploy/local/dev/docker-compose.yml",
  ],
  "service": "service_name",
  "workspaceFolder": "/workspace",
  "containerUser": "vscode",
  "updateRemoteUserUID": true,
  "initializeCommand": "make dev-image",
  "shutdownAction": "stopCompose",
  "containerEnv": {
    "PACKAGE_REGISTRY_URL": "${localEnv:PACKAGE_REGISTRY_URL}",
  },
}

PACKAGE_REGISTRY_URL is used in make dev-image which under the hood does a docker build --build-arg="PACKAGE_REGISTRY_URL" --tag=image_name_in_docker_compose .

Where can I define PACKAGE_REGISTRY_URL?

  • /etc/profile?
  • ~/.profile?
  • ~/.bashrc?

Does that work with zsh as well (which is my preferred shell)? Any advises/tip welcomed.

I have a bit struggling because the shell starting the make dev-image often has issues knowing that env var and I would like further clarity on this.

Thanks a lot for your support.

Still an issue.

Still an issue

I have been trying to export PACKAGE_REGISTRY_URL=whatever and print env before my actual initialization command

  • I see that SHELL=/usr/bin/zsh
  • But whenever I write that export in ~/.zshenv (which I thought would be correct as it is a non-login non-interactive shell call), ~/.zprofile, ~/.zshrc, I don’t get my exported variable.

Found the issue: Cursor Devcontainer: Lifecycle commands does not work with symlinked dotfiles