WARNING: Published ports are discarded when using host network mode 解决方法

本文解析了Docker启动时出现的特定警告信息,深入探讨了在使用--network=host模式下指定-p参数为何无效,以及如何通过选择正确的网络模式如bridge模式来避免此类警告,确保端口正确映射。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:

     docke启动时总是遇见标题中的警告,-p 8889:8888的设置也不起任何作用。

原因:

    docker启动时指定--network=host或-net=host,如果还指定了-p或-P,那这个时候就会有此警告,并且通过-p或-P设置的参数将不会起到任何作用,端口号会以主机端口号为主,重复时则递增。

解决:

    解决的办法就是使用docker的其他网络模式,例如--network=bridge,这样就可以解决问题,

docker的网络模式:

   bridge模式: Docker的默认设置

   host模式

   none模式

   container模式: 使用时要指定容器名

   overlay模式

 

 

 

[root@localhost rules]# vim node-up.rules [root@localhost rules]# docker rm -f prometheus prometheus [root@localhost rules]# docker run -d --name prometheus -p 9090:9090 -v /prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /prometheus/rules:/usr/local/prometheus/rules --net host prom/prometheus WARNING: Published ports are discarded when using host network mode fb4c4de5d4ab0f8b981d70ed06f299c370716bfd0f301cb78b00757c26dccc68 [root@localhost rules]# vi /prometheus/prometheus.yml [root@localhost rules]# docker rm -f prometheus prometheus [root@localhost rules]# docker run -d --name prometheus -p 9090:9090 -v /prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /prometheus/rules:/usr/local/prometheus/rules --net host prom/prometheus WARNING: Published ports are discarded when using host network mode f89a3c1c87dacc072c0e3f276c894b4af6577bff3bb555d045ab101ee9f545f1 [root@localhost rules]# docker restart prometheus prometheus [root@localhost rules]# vim node-up.rules [root@localhost rules]# docker rm -f prometheus prometheus [root@localhost rules]# docker run -d --name prometheus -p 9090:9090 -v /prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /prometheus/rules:/usr/local/prometheus/rules --net host prom/prometheus WARNING: Published ports are discarded when using host network mode b37c19541089a54f2db765f3ae51379c0d384e40f3697022109f365c97c81673 [root@localhost rules]# vi /prometheus/prometheus.yml [root@localhost rules]# docker run --name prometheus -d -p 9090:9090 -v /root/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /root/prometheus/groups/:/usr/local/prometheus/groups/ -v /root/prometheus/rules/:/usr/local/prometheus/rules/ prom/prometheus docker: Error response from daemon: Conflict. The container name "/prometheus" is already in use by container "b37c19541089a54f2db765f3ae51379c0d384e40f3697022109f365c97c81673". You have to remove (or rename) that container to be able to reuse that name. See 'docker run --help'. 这样配置之后却没有在普罗米修斯的rules看到node-rule
最新发布
06-14
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值