Is there a Windows equivalent to bash's export
? I want to set an environment variable so that it's available to subsequent commands. I don't want to setx
a permanent env variable.
For example 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.
PS C:\Users\Owner> docker run -e FOO=bar centos env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=05b90a09d7fd
FOO=bar
HOME=/root
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 each 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 I can create an env file and pass that to docker run
but I'm trying to avoid that.
PS: I asked this question here but didn't get an answer: https://forums.docker.com/t/how-to-set-environment-variables-in-command-prompt-so-theyre-passed-in-docker-run-e-foo-e/106776/4