Unable to bind Windows environment variables to Docker Compose Environment

Viewed 2137

I currently have a compose file for a Windows .Net service, and I want to be able to pass through a user-space environment variable:

Set from powershell:

powershell [Environment]::SetEnvironmentVariable(\"PREVIOUSLY_SET_WINDOWS_ENV_VARIABLE\", $env:computername, \"User\")

Docker compose file:

services:
  myservice.commandline:
    image: myservice.commandline:dev
    build:
      args:
        source: ${DOCKER_BUILD_SOURCE}
    volumes:
      - .\myservice.commandline:C:\app
      - ~\msvsmon:C:\msvsmon:ro
    entrypoint: powershell -Command [System.Threading.Thread]::Sleep([System.Threading.Timeout]::Infinite)
    environment:
      - MY_VARIABLE_NAME=${PREVIOUSLY_SET_WINDOWS_ENV_VARIABLE}
    labels:
      - "com.microsoft.visualstudio.targetoperatingsystem=windows"

This does not work - the environment variable shows as blank.

- MY_VARIABLE_NAME=${PREVIOUSLY_SET_WINDOWS_ENV_VARIABLE} doesn't work.

How do I pass a windows environment variable through to a Docker Compose environment variable?

Background:

  • ${PREVIOUSLY_SET_WINDOWS_ENV_VARIABLE} doesn't work.
  • $PREVIOUSLY_SET_WINDOWS_ENV_VARIABLE doesn't work.
  • $(PREVIOUSLY_SET_WINDOWS_ENV_VARIABLE) doesn't work.
  • ${%PREVIOUSLY_SET_WINDOWS_ENV_VARIABLE%} doesn't work.
0 Answers
Related