I wonder how I get an Environment variable from docker inspect.
when i run
docker inspect -f "{{.Config.Env.PATH}} " 1e2b8689cf06
i get the following
FATA[0000] template: :1:9: executing "" at <.Config.Env.PATH>: can't evaluate field PATH in type interface {}
Fetch Using docker exec Command Here, we are executing the /usr/bin/env utility inside the Docker container. Using this utility, you can view all the environment variables set inside Docker containers.
Overriding ENV ValuesContainers started from it, have access to ENV variables defined in the Dockerfile. However, those values can be overridden by providing single environment variables, or env_files, from which environment variables are parsed and passed into the container.
The variables from env come from the Dockerfile or command, docker itself and whatever the entrypoint sets.
With a Command Line Argument The command used to launch Docker containers, docker run , accepts ENV variables as arguments. Simply run it with the -e flag, shorthand for --env , and pass in the key=value pair: sudo docker run -e POSTGRES_USER='postgres' -e POSTGRES_PASSWORD='password' ...
You can get directly with a command similar to
docker inspect --format '{{ index (index .Config.Env) 1 }}' 797
which shows for me
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
You will notice that replacing the 1
by 0
like
docker inspect --format '{{ index (index .Config.Env) 0 }}' 797
gives
DISPLAY=:0
In fact I had noticed the following for various docker inspect
from a more general to a more precise display
docker inspect --format '{{ (.NetworkSettings.Ports) }}' 87c map[8000/tcp:[map[HostIp:0.0.0.0 HostPort:49153]]] docker inspect --format '{{ ((index .NetworkSettings.Ports "8000/tcp") 0) }}' 87c [map[HostIp:0.0.0.0 HostPort:49153]] docker inspect --format '{{ index (index .NetworkSettings.Ports "8000/tcp") 0 }}' 87c map[HostIp:0.0.0.0 HostPort:49153] docker inspect --format '{{ (index (index .NetworkSettings.Ports "8000/tcp") 0).HostIp }}' 87c 0.0.0.0 docker inspect --format '{{ (index (index .NetworkSettings.Ports "8000/tcp") 0).HostPort }}' 87c 49153
Note: docker inspect -f
works and is shorter, of course, I posted the "old" syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With