I have performed some tests and it seems that the container only has access to its own Windows system environment variables. Is there a way for the container to access the host's system environment variables?
Asked
Active
Viewed 1,583 times
1
-
if you add them with the run command yes – jonathan Heindl May 23 '19 at 20:53
-
if nohing else helps you can also have a script running outside the container that writes them to a file and map that with a volume and read it the file in the container – jonathan Heindl May 23 '19 at 20:54
-
I have an understanding of Docker environment variables, how to define them in a Dockerfile and how to pass them to the docker run command's -e flag. However, I need a Windows system environment variable defined and they are not one in the same. I tried using the setx.exe command in the Dockerfile to set the Windows environment variable in the container itself but Dockerfile environment variables are not scoped to the RUN command so that didn't work either. – chad May 23 '19 at 21:12
-
well yeah that wont work and I doubt it will docker is not meant to be able to modify the host system like that only thing you can do is run a recurrung script over a mapped file and set the environm,ent accordinglky on the host system – jonathan Heindl May 23 '19 at 21:17
-
It executes against the container and creates a Windows environment variable. However, the Dockerfile RUN can access Docker environment variables. So, I'm unable to set it dynamically via the -e flag. – chad May 24 '19 at 01:09
1 Answers
2
Docker containers are isolated from the host and each other. Unless you explicitly pass things in or manually grant access, a container can't access the host's environment variables, filesystems, init system, global configuration, display, physical devices, ....
The only way to do pass through host environment variables is with the docker run -e
option or other equivalents like the Docker Compose environment:
block. In both docker run -e
and Docker Compose, specifying a variable name without a value will pass it through from the host, but it must be explicitly named. You cannot specify this in a Dockerfile or any other attribute of an image.

David Maze
- 130,717
- 29
- 175
- 215