如何使用容器ID获取容器ID

时间:2020-06-26 21:00:43

标签: image docker containers pod

我创建docker镜像,如下信息所示:

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
9e4b39772695        modelorigin         "/bin/bash"         2 hours ago         Up 2 hours                              brave_ellis

映像是使用Dockerfile构建的:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1.202-bionic as build
ARG BUILDCONFIG=RELEASE
ARG VERSION=1.0.0

WORKDIR .
COPY . /build/
COPY Model/Model.sln /build/Model/

RUN dotnet build ./build/Model/Model.sln
RUN dotnet restore ./build/Model/Model.sln

WORKDIR /build/Model
RUN dotnet publish Model.sln -c $BUILDCONFIG -o out /p:Version=$VERSION

使用以下命令按Pod列出容器图像,但仍无法获得容器ID为9e4b39772695的容器ID。

$ kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{.image}{", "}{end}{end}' |\ 
> sort

etcd-minikube:  k8s.gcr.io/etcd-amd64:3.1.12, 
kube-addon-manager-minikube:    k8s.gcr.io/kube-addon-manager:v8.6, 
kube-apiserver-minikube:    k8s.gcr.io/kube-apiserver-amd64:v1.10.0, 
kube-controller-manager-minikube:   k8s.gcr.io/kube-controller-manager-amd64:v1.10.0, 
kube-dns-86f4d74b45-6qnzk:  k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.8, k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.8, k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.8, 
kube-proxy-gw6rc:   k8s.gcr.io/kube-proxy-amd64:v1.10.0, 
kube-scheduler-minikube:    k8s.gcr.io/kube-scheduler-amd64:v1.10.0, 
kubernetes-dashboard-5498ccf677-dbb5l:  k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1, 
storage-provisioner:    gcr.io/k8s-minikube/storage-provisioner:v1.8.1, 

我还尝试了以下命令来获取Pod ID,但一无所获...

$ kubectl get pod -o jsonpath='{range .items[?(@.status.containerStatuses[].containerID=="docker://9e4b397726952c966bd18f13470f27a6240f5a0effcf8b88f317860069fc7312")]}{.metadata.name}{end}' 

如何获取带有图像的容器ID(容器ID)? 谢谢

0 个答案:

没有答案