gpt4 book ai didi

docker - 在 Kubernetes 中使用 dind 运行私有(private)仓库

转载 作者:行者123 更新时间:2023-12-05 04:23:54 27 4
gpt4 key购买 nike

我尝试将我的私有(private) docker 镜像与 docker-dind 容器一起运行,以便能够从 Kubernetes 中的私有(private)镜像运行 docker 命令。我唯一的问题是 docker run 命令不读取 docker-secrets,因此要求运行 docker login 失败。如何将凭据传递给 docker run 命令?

这是我的 Kubernetes 部署部分:

  containers:
- name: docker-private
image: docker:20.10
command: ['docker', 'run', '-p', '80:8000', 'private/image:latest' ]
resources:
requests:
cpu: 10m
memory: 256Mi
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
envFrom:
- secretRef:
name: docker-secret-keys
- name: dind-daemon
image: docker:20.10-dind
command: ["dockerd", "--host", "tcp://127.0.0.1:2375"]
resources:
requests:
cpu: 20m
memory: 512Mi
securityContext:
privileged: true
volumeMounts:
- name: docker-graph-storage
mountPath: /var/lib/docker

编辑我确实有我的证书作为 Kubernetes secret ,我尝试将其安装到正在运行的 docker,但直到现在都没有成功 :(

apiVersion: v1
data:
.dockerconfigjson: eyJhXXXXXXdoihfc9w8fwpeojfOFwhfoiuwehfo8wfhoi2ehfioewNlcm5hbWUiOiJlbGRhcmVudGas4hti45ytg45hgiVsZGFXXXXXXyQGVudG9yLmlvIiwiYXV0aCI6IlpXeGtZWEpsYm5SdmNqb3dObVl4WmpjM1lTMDVPRFZrTFRRNU5HRXRZVEUzTXkwMk5UYzBObVF4T0RjeFpUWT0ifX19XXXXXXXXXXX
kind: Secret
metadata:
name: staging-docker-keys
namespace: staging
resourceVersion: "6383"
uid: a7yduyd-xxxx-xxxx-xxxx-ae2ede3e4ed
type: kubernetes.io/dockerconfigjson

最终目标是让“内部 docker”(运行 private/image:latest)能够运行任何 docker 命令,而无需在每个命令之前登录。

最佳答案

docker:dind 将在 /certs 中创建 ca、服务器、客户端证书。只需创建 emptyDir 卷即可共享证书。

apiVersion: v1
kind: Pod
metadata:
name: myapp
labels:
name: myapp
spec:
volumes:
- name: docker-tls-certdir
emptyDir: {}
containers:
- name: docker-private
image: docker:20.10
command: ['docker', 'run', '-p', '80:8000', 'nginx' ]
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
volumeMounts:
- name: docker-tls-certdir
mountPath: /certs
- name: dind-daemon
image: docker:20.10-dind
command: ["dockerd", "--host", "tcp://127.0.0.1:2375"]
securityContext:
privileged: true
volumeMounts:
- name: docker-tls-certdir
mountPath: /certs

关于docker - 在 Kubernetes 中使用 dind 运行私有(private)仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73606795/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com