dind 中的容器访问同一个 Kubernetes pod 中的另一个容器

Container in dind access another container in the same Kubernetes pod

在 Kubernetes pod 中,我有:

我知道如果 dind 想要访问 fluentd,它只需要连接到 localhost:9880。但是,如果 busybox 想要访问 fluentd 怎么办,如下图所示。我应该使用哪个地址?

这些提示可能对您有所帮助:

1.第一种方法

从 docker:latest 容器内部,您最初尝试访问它的地方,它可以在为 docker:dind 容器设置的任何主机名上使用。在这种情况下,您使用了 --name dind,因此 curl dind:busybox_port 将为您提供标准。

然后您可以从 docker:dind 容器 (busybox) 连接到 fluentd,它将在 localhost:9880.

上可用

2。第二种方法

另一种方法是 EXPOSE [/...] 在这种情况下,我们假设 busyboox 和 fluentd 在不同的网络中 您也可以在 docker 运行 命令中指定它,例如:

$ docker run --expose=1234 busybox

但是 EXPOSE 将不允许通过定义的端口与同一网络之外的容器或主机进行通信。要实现这一点,您需要发布端口。

发布 端口并将它们映射到主机

要在 运行 连接容器时发布端口,请在 docker 运行 上使用 -p 标志发布并映射一个或更多端口,或 -P 标志发布所有暴露的端口并将它们映射到 high-order 端口。

$ docker run -p 80:80/tcp -p 80:80/udp busybox

然后使用 localhost:9880

从 busybox 连接到 fluentd

您可以在此处找到更多信息:docker-in-docker

希望对您有所帮助。