我想了解是否可以使用bash脚本读取容器的元数据属性(特别是标签)。
例如,如果有一个Dockerfile如下:
FROM busybox
LABEL abc = abc_value1
如果我根据上面的文件构建并运行一个镜像,就像这样:
docker build . -t image1
docker run -ti image1 /bin/bash
有没有办法在bash shell中访问“abc”标签的值?如果有,该怎么做?
我想了解是否可以使用bash脚本读取容器的元数据属性(特别是标签)。
例如,如果有一个Dockerfile如下:
FROM busybox
LABEL abc = abc_value1
如果我根据上面的文件构建并运行一个镜像,就像这样:
docker build . -t image1
docker run -ti image1 /bin/bash
有没有办法在bash shell中访问“abc”标签的值?如果有,该怎么做?
FROM ubuntu:16.04
RUN apt-get update \
&& apt-get install curl -y
LABEL abc = abc_value1
构建和运行
docker build -t image1 .
docker run -v /var/run/docker.sock:/var/run/docker.sock -it image1 /bin/bash
从容器内部
curl --unix-socket /var/run/docker.sock http:/containers/$(hostname)/json