本文介绍了进行 Docker Inspect 时如何获取 ENV 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何从 docker inspect 获取环境变量.
I wonder how I get an Environment variable from docker inspect.
当我跑步时
docker inspect -f "{{.Config.Env.PATH}} " 1e2b8689cf06
我得到以下
FATA[0000] template: :1:9: executing "" at <.Config.Env.PATH>: can't evaluate field PATH in type interface {}
推荐答案
用类似的命令直接获取
docker inspect --format '{{ index (index .Config.Env) 1 }}' 797
为我展示
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
您会注意到将 1
替换为 0
就像
You will notice that replacing the 1
by 0
like
docker inspect --format '{{ index (index .Config.Env) 0 }}' 797
给予
DISPLAY=:0
事实上,我已经注意到以下各种 docker inspect
从更一般到更精确的显示
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
注意:docker inspect -f
有效并且更短,当然,我发布了旧"语法.
Note: docker inspect -f
works and is shorter, of course, I posted the "old" syntax.
这篇关于进行 Docker Inspect 时如何获取 ENV 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!