centos7 docker 宿主机不能访问容器问题解决
centos7安装docker ,再下载rabbitmq镜像,启动容器后无法访问容器内的服务,防火墙也关闭了,但是还是不行,后来重新设置了网卡,就可以了,解决过程如下:
#下载镜像
docker pull rabbitmq:3.7.15
#启动docker容器
docker run -d --name rabbitmq --publish 5671:5671 --publish 5672:5672 --publish 4369:4369 --publish 25672:25672 --publish 15671:15671 --publish 15672:15672 rabbitmq:3.7.15
docker exec -it rabbitmq /bin/bash
rabbitmq-plugins enable rabbitmq_management
#访问rabbitmq服务,正常应该是能访问的,实际访问不了
[root@localhost ~]# curl http://127.0.0.1:15672
curl: (56) Recv failure: Connection reset by peer
#停止docker
systemctl stop docker
#docker0
ip link set dev docker0 down
#删除docker0网桥
brctl delbr docker0
#防火墙设置,后来发现这一步不用执行可以
iptables -t nat -F POSTROUTING
#增加docker0 网桥
brctl addbr docker0
#增加网卡
ip addr add 172.16.10.1/24 dev docker0
#启用网卡
ip link set dev docker0 up
#重启docker服务
systemctl restart docker
正常访问
[root@localhost ~]# curl http://127.0.0.1:15672
<!doctype html>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<html>
<head>
<title>RabbitMQ Management</title>
<script src="js/ejs-1.0.min.js" type="text/javascript"></script>
<script src="js/jquery-1.12.4.min.js" type="text/javascript"></script>
<script src="js/jquery.flot-0.8.1.min.js" type="text/javascript"></script>
<script src="js/jquery.flot-0.8.1.time.min.js" type="text/javascript"></script>
<script src="js/sammy-0.7.6.min.js" type="text/javascript"></script>
<script src="js/json2-2016.10.28.js" type="text/javascript"></script>
<script src="js/base64.js" type="text/javascript"></script>
<script src="js/global.js" type="text/javascript"></script>
<script src="js/main.js" type="text/javascript"></script>
<script src="js/prefs.js" type="text/javascript"></script>
<script src="js/formatters.js" type="text/javascript"></script>
<script src="js/charts.js" type="text/javascript"></script>
<link href="css/main.css" rel="stylesheet" type="text/css"/>
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<!--[if lte IE 8]>
<script src="js/excanvas.min.js" type="text/javascript"></script>
<link href="css/evil.css" rel="stylesheet" type="text/css"/>
<![endif]-->
</head>
<body>
<div id="outer"></div>
<div id="debug"></div>
<div id="scratch"></div>
</body>
</html>
欢迎关注技术公众号: