Docker中安装Centos7后访问该Centos7中的服务

Docker中安装Centos7后访问该Centos7中的服务

说明

该环境是这样的:
在这里插入图片描述
如果还没在Docker中安装过Centos7的话,请移步到:Docker中安装Centos7操作系统

一、安装Iptables

1、检查是否安装

[root@shendu ~]# iptables --version
iptables v1.4.21
[root@shendu ~]# 

2、如果没有安装请自行使用命令:[root@shendu ~]# yum -y install iptables.services进行安装

3、启动iptables

[root@shendu ~]# 
[root@shendu ~]# systemctl start iptables
[root@shendu ~]# 

4、清空现有的规则,保存规则,查看规则

[root@shendu ~]# 
[root@shendu ~]# iptables -F
[root@shendu ~]# 
[root@shendu ~]# 
[root@shendu ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@shendu ~]# 
[root@shendu ~]# 
[root@shendu ~]# 
[root@shendu ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy DROP)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (0 references)
target     prot opt source               destination         

Chain DOCKER-ISOLATION (0 references)
target     prot opt source               destination         
[root@shendu ~]# 

5、重新启动iptables

[root@shendu ~]# 
[root@shendu ~]# systemctl restart iptables
[root@shendu ~]# 
[root@shendu ~]# 

发现现在客户端已经连接不上Docker安装的Centos7服务器了,但是安装Docker的系统还可以连接
在这里插入图片描述

果断把防火墙关闭了一下,又重新连接了一下,又可以了。

使用命令:systemcl stop iptables关闭iptables

二、配置Iptables

  • 进入iptables的配置文件
[root@shendu ~]# vi /etc/sysconfig/iptables
  • 加上下面这一条,是我映射的docker的端口
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10000  -j ACCEPT

在这里插入图片描述

发布了101 篇原创文章 · 获赞 76 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_17623363/article/details/103254831
今日推荐