Skip to main content

Environment variables in devcontainer.json

If you're combining SSH provider with using environment variables in your .devcontainer.json, please follow the steps below to make sure that your environment variables are properly set on the remote machine.

Steps

  1. Prepare a .devcontainer.json to include ${localEnv:<VARIABLE_NAME>} directive.
    Example .devcontainer.json:
{
"name": "Node.js",
"image": "mcr.microsoft.com/devcontainers/javascript-node:${localEnv:IMAGE_VERSION}"
}
  1. Prepare an entry in a local .ssh/config to include SetEnv <VARIABLE_NAME>=<VARIABLE_VALUE> directive.
    Example .ssh/config:
Host <REMOTE-SSH-SERVER>
SetEnv IMAGE_VERSION=0-18-bullseye
  1. Log to your remote machine and in the /etc/ssh/sshd_config add an entry AcceptEnv <VARIABLE_NAME>.
    For example:
AcceptEnv IMAGE_VERSION
  1. Restart SSH service on your remote machine.
    For example on Debian Linux:
systemctl restart ssh.service
  1. Run a devpod up command:
devpod up <GITHUB-REPOSITORY-URL> --ide=none