This works as expected with Docker for Windows in a Windows Terminal PowerShell Command Prompt. The FOO environment variable value is available in the container.
But how do I set an env variable in Windows with the equivalent of bash export so that it’s available without setting the value directly on the docker run command?
You can see here that set does not pass the value of FOO to the container.
PS C:\Users\Owner> set FOO=bar
PS C:\Users\Owner> docker run -e FOO centos env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=6642033b3753
HOME=/root
I know not all env variables get passed to the container but I’m specifying the environment variable explicitly with -e. This works on macos/linux I’m just trying to learn the equivalent on Windows.
Additionally, the operator can set any environment variable in the container by using one or more -e flags, even overriding those mentioned above, or already defined by the developer with a Dockerfile ENV . If the operator names an environment variable without specifying a value, then the current value of the named variable is propagated into the container’s environment
You really don’t need to export the variable first with export FOO=bar or set FOO=bar ,
you can set them directly in the docker run command like this docker run -e Foo=bar ubuntu env
I know but I want to set the variables once and not have to repeat the values on the docker command line. In my real use case I have to run multiple docker run commands. And I know I could create an env file but trying to avoid that.
Surely Windows has the equivalent of exporting an env variable?