做Docker Inspect时如何获得ENV变量 [英] How to get ENV variable when doing Docker Inspect

查看:648
本文介绍了做Docker Inspect时如何获得ENV变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何从Docker检查得到一个环境变量。

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

docker inspect --format '{{ index (index .Config.Env) 0 }}' 797

DISPLAY=:0

事实上,我注意到以下各种 docker检查从更一般到更精确的显示

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

注意:$ $ c> docker inspect -f 的作品更短,当然,我发布了旧语法。

Note: docker inspect -f works and is shorter, of course, I posted the "old" syntax.

这篇关于做Docker Inspect时如何获得ENV变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆