gpt4 book ai didi

docker - 如何公开无类型docker容器的端口?

转载 作者:行者123 更新时间:2023-12-02 20:07:53 25 4
gpt4 key购买 nike

我创建了两个 docker 容器,其中一个的网络类型为none,另一个为桥类型。在创建Docker容器的过程中,使用以下命令将它们的端口映射为主机端口。

docker run -p host_port:container_port image


使用管道将无类型容器添加到网络中,因此无类型容器也具有IP地址,并且可以连接到外部网络。
我尝试使用netcat访问容器端口,但是无法访问类型为none的容器的端口。使用命令“docker port container_name”,我看不到无类型容器中的端口,但可以看到桥接类型容器的映射端口。
我使用的Netcat命令是:

nc -l localhost host_port ----->in the host

nc localhost container_port ----->in the container


反之亦然。

最佳答案

Docker网络-无,不会为该容器配置任何IP,也无权访问外部网络以及其他容器。它确实具有回送地址,可用于运行批处理作业。

# docker run -it --network=none ubuntu:14.04 /bin/bash
root@66308c6686be:/# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

#

# docker inspect 66308c6686be | grep -i ipaddr
"SecondaryIPAddresses": null,
"IPAddress": "",
"IPAddress": "",

有关docker网络的更多信息,请引用 here.

关于docker - 如何公开无类型docker容器的端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48538375/

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