简体   繁体   English

无法通过 localhost 连接到 kubernetes pod 中的其他容器

[英]Cannot connect to other container in kubernetes pod through localhost

I'm trying to launch docker-in-docker so that I can connect to it in a different container in the same Kubernetes pod.我正在尝试启动 docker-in-docker 以便我可以在同一个 Kubernetes pod 中的不同容器中连接到它。 I am using the following yaml:我正在使用以下 yaml:

apiVersion: batch/v1
kind: Job
metadata:
  name: {{job_name}}
  labels:
    taskType: store_v510
    taskName: {{task_name}}
spec:
  template:
    spec:
      activeDeadlineSeconds: 86400
      volumes:
        - name: hdfs-volume
          configMap:
            name: hdfs-config
            items:
              - key: core-site.xml
                path: core-site.xml
              - key: hadoop-env.sh
                path: hadoop-env.sh
              - key: hdfs-site.xml
                path: hdfs-site.xml
              - key: log4j.properties
                path: log4j.properties
        - name: download-dir
          hostPath:
              path: /tmp/store_pipeline
        - name: docker-graph-storage 
          emptyDir: {}
      containers:
        - name: {{job_name}}
          envFrom:
          - configMapRef:
              name: job-configs
          env: 
          - name: DOCKER_HOST 
            value: tcp://localhost:2375
          volumeMounts: 
          - mountPath: /tmp/store_pipeline
            name: download-dir
          image: registry.com.cn/com/store_pipeline:0.1
          imagePullPolicy: Always
          resources:
            requests:
              cpu: 2
              memory: 32Gi
              nvidia.com/gpu: 0
            limits:
              cpu: 2
              memory: 40Gi
              nvidia.com/gpu: 0
          command: ["bash", "run_store_pipeline.sh", "--data_dir", "{{data_dir}}", "--config_dir", "{{config_dir}}", "--output_dir", "{{output_dir}}"]
        - name: dind-daemon 
          image: registry.com.cn/com/1.12.6-dind
          resources: 
              requests: 
                  cpu: 20m 
                  memory: 512Mi 
          securityContext: 
              privileged: true 
          volumeMounts: 
            - name: docker-graph-storage 
              mountPath: /var/lib/docker 
          command: []

Based on the documentation I see, I should be able to connect to the docker-in-docker docker daemon by setting DOCKER_HOST = tcp://localhost:2375.根据我看到的文档,我应该能够通过设置 DOCKER_HOST = tcp://localhost:2375 连接到 docker-in-docker docker 守护进程。 However, I'm not able to do so.但是,我不能这样做。

I notice that if I test it locally and run these two containers in the same docker network, I'm able to connect them by specifying the actual container name (ie tcp://dind-daemon:2375).我注意到,如果我在本地测试它并在同一个 docker 网络中运行这两个容器,我可以通过指定实际容器名称(即 tcp://dind-daemon:2375)来连接它们。 Thanks!谢谢!

Your setup seems to be correct.您的设置似乎是正确的。 I assume that the docker image is comparable to a current docker image from the public registry.我假设 docker 映像与来自公共注册表的当前 docker 映像相当。

That docker-in-docker usually listens only for TLS secured requests on port 2376.该 docker-in-docker 通常仅在端口 2376 上侦听 TLS 安全请求。

If you want to be able to use it on 2375 without mutual TLS authentication you need to set the environment variable DOCKER_TLS_CERTDIR to an empty value.如果您希望能够在没有相互 TLS 身份验证的情况下在 2375 上使用它,您需要将环境变量DOCKER_TLS_CERTDIR设置为空值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kubernetes:同一个 Pod 中的两个容器无法通过 localhost 连接 - Kubernetes : two containers in same pod cannot connect through localhost kubernetes pod无法连接(通过服务)到self,只能连接到其他pod容器 - kubernetes pod can't connect (through service) to self, only to other pod-containers Kubernetes - 尽管存在服务,但无法从集群内的其他 pod 连接到 MySQL pod - Kubernetes - cannot connect to MySQL pod from other pod inside cluster although service exists Kubernetes - 使用名称而不是“localhost”在pod中进行容器通信? - Kubernetes - container communication within a pod using names instead of 'localhost'? 尝试通过localhost连接到Docker容器 - Trying to connect to docker container through localhost 无法连接到本地主机中的 MySQL docker 容器 - Cannot connect to MySQL docker container in localhost docker容器中的cronjob无法连接到其他容器 - cronjob in docker container cannot connect to other container Kubernetes Pod没有将卷绑定到容器 - Kubernetes pod not binding volumes to container Kubernetes部署,Pod和容器概念 - Kubernetes Deployments, Pod and Container concepts 如何将来自一个容器的所有流量路由到同一个 Kubernetes pod 中的另一个容器? - How to route all traffic from a container through another container in the same Kubernetes pod?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM