无法从外部到达 docker 个容器
Unable to reach docker container from outside
我有一个相当直接的 Docker 堆栈设置。我此时在集群中有一个节点(管理器节点)。在这个集群上,我 运行 使用一个 portainer 代理 (portainer_agent) 来关注节点和 portainer web 界面 (portainer_portainer)。
我 运行 遇到的问题是,当我通过 ssh 连接到节点时,我可以在其发布的端口 (localhost:9000
) 上访问 portainer_portainer。但是,当我尝试从我的桌面浏览器(而不是在集群节点上)访问节点外部 IP 地址上的同一个端口(10.0.0.6:9000
)时,我无法从容器中获取任何数据。我做错了什么吗?我已经包括了我的 docker 检查 portainer_portainer.
docker 版本 linux
Docker version 19.03.12, build 48a66213fe
portainer_portainer 检查
ID: j62wg3sgry5326h4gli3apvxe
Name: portainer_portainer
Labels:
com.docker.stack.image=portainer/portainer
com.docker.stack.namespace=portainer
Service Mode: Replicated
Replicas: 1
UpdateStatus:
State: completed
Started: 57 seconds ago
Completed: 44 seconds ago
Message: update completed
Placement:
Constraints: [node.role == manager]
UpdateConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Update order: stop-first
RollbackConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Rollback order: stop-first
ContainerSpec:
Image: portainer/portainer:latest@sha256:f8c2b0a9ca640edf508a8a0830cf1963a1e0d2fd9936a64104b3f658e120b868
Args: -H tcp://tasks.agent:9001
Mounts:
Target: /data
Source: /mnt/portainer/data
ReadOnly: false
Type: bind
Resources:
Networks: portainer_agent_network
Endpoint Mode: vip
Ports:
PublishedPort = 8000
Protocol = tcp
TargetPort = 8000
PublishMode = ingress
PublishedPort = 9000
Protocol = tcp
TargetPort = 8000
PublishMode = ingress
编辑:经进一步检查。这些容器实际上是可以到达的。但是,它们只有在连接到我的防火墙上的 VPN 服务时才能访问。这告诉我该服务正在正确发布,但它们在我的本地网络中仍然不可用(这将是我继续 docker 的关键)。
所以,经过一番挖掘,我似乎没有很好地说明我的问题。我的家庭网络位于 10.0.0.0/24
子网上,因为它是默认的 docker 入口网络。我重建了我的 docker swarm,并按照官方 docker 关于替换默认入口网络的教程完成了这项工作。我使用的命令如下:
docker network rm ingress
docker network create --driver overlay --ingress --subnet=10.0.1.0/24 --gateway=10.0.1.2 ingress
完成所有这些后,我重新初始化了 docker 服务。一切都出现了,并且可以在我的网络上使用。
我有一个相当直接的 Docker 堆栈设置。我此时在集群中有一个节点(管理器节点)。在这个集群上,我 运行 使用一个 portainer 代理 (portainer_agent) 来关注节点和 portainer web 界面 (portainer_portainer)。
我 运行 遇到的问题是,当我通过 ssh 连接到节点时,我可以在其发布的端口 (localhost:9000
) 上访问 portainer_portainer。但是,当我尝试从我的桌面浏览器(而不是在集群节点上)访问节点外部 IP 地址上的同一个端口(10.0.0.6:9000
)时,我无法从容器中获取任何数据。我做错了什么吗?我已经包括了我的 docker 检查 portainer_portainer.
docker 版本 linux
Docker version 19.03.12, build 48a66213fe
portainer_portainer 检查
ID: j62wg3sgry5326h4gli3apvxe
Name: portainer_portainer
Labels:
com.docker.stack.image=portainer/portainer
com.docker.stack.namespace=portainer
Service Mode: Replicated
Replicas: 1
UpdateStatus:
State: completed
Started: 57 seconds ago
Completed: 44 seconds ago
Message: update completed
Placement:
Constraints: [node.role == manager]
UpdateConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Update order: stop-first
RollbackConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Rollback order: stop-first
ContainerSpec:
Image: portainer/portainer:latest@sha256:f8c2b0a9ca640edf508a8a0830cf1963a1e0d2fd9936a64104b3f658e120b868
Args: -H tcp://tasks.agent:9001
Mounts:
Target: /data
Source: /mnt/portainer/data
ReadOnly: false
Type: bind
Resources:
Networks: portainer_agent_network
Endpoint Mode: vip
Ports:
PublishedPort = 8000
Protocol = tcp
TargetPort = 8000
PublishMode = ingress
PublishedPort = 9000
Protocol = tcp
TargetPort = 8000
PublishMode = ingress
编辑:经进一步检查。这些容器实际上是可以到达的。但是,它们只有在连接到我的防火墙上的 VPN 服务时才能访问。这告诉我该服务正在正确发布,但它们在我的本地网络中仍然不可用(这将是我继续 docker 的关键)。
所以,经过一番挖掘,我似乎没有很好地说明我的问题。我的家庭网络位于 10.0.0.0/24
子网上,因为它是默认的 docker 入口网络。我重建了我的 docker swarm,并按照官方 docker 关于替换默认入口网络的教程完成了这项工作。我使用的命令如下:
docker network rm ingress
docker network create --driver overlay --ingress --subnet=10.0.1.0/24 --gateway=10.0.1.2 ingress
完成所有这些后,我重新初始化了 docker 服务。一切都出现了,并且可以在我的网络上使用。