Docker之端口映射访问不到外网

  1. docker 镜像启动成功但是无法访问

  2. 首先判断是否为防火墙关闭

    1:查看防火状态

    systemctl status firewalld

    service  iptables status 

    2:暂时关闭防火墙

    systemctl stop firewalld

    service  iptables stop 

    3:永久关闭防火墙

    systemctl disable firewalld

    chkconfig iptables off

    4:重启防火墙

    systemctl enable firewalld

    service iptables restart  

    5:永久关闭后重启

    //暂时还没有试过

    chkconfig iptables on

  3. 解决办法:
    vi /etc/sysctl.conf
    或者
    vi /usr/lib/sysctl.d/00-system.conf
    添加如下代码:
    net.ipv4.ip_forward=1
    重启network服务
    systemctl restart network
    查看是否修改成功
    sysctl net.ipv4.ip_forward
    如果返回为“net.ipv4.ip_forward = 1”则表示成功了

  4. 外网不能访问docker容器解决方案

[root@linux ~]# systemctl stop firewalld.service
[root@linux ~]# systemctl disable firewalld.service
[root@linux ~]# sed -ri '/SELINUX=enforcing/cSELINUX=disabled' /etc/sysconfig/selinux
[root@linux ~]# setenforce 0

[root@linux ~]# echo "1" > /proc/sys/net/ipv4/ip_forward

[root@linux ~]# sysctl -p

net.ipv4.ip_forward = 1

[root@linux ~]#[root@linux ~]# docker run -d --name tomcat02 -p 9527:8080 tomcat:latest

 

[root@linux ~]# docker exec -it tomcat02 /bin/bash
root@2cb65acbee53:/usr/local/tomcat# ls -l
total 136
-rw-r--r--. 1 root root 18982 Apr  3 12:06 BUILDING.txt
-rw-r--r--. 1 root root  5409 Apr  3 12:06 CONTRIBUTING.md
-rw-r--r--. 1 root root 57092 Apr  3 12:06 LICENSE
-rw-r--r--. 1 root root  2333 Apr  3 12:06 NOTICE
-rw-r--r--. 1 root root  3255 Apr  3 12:06 README.md
-rw-r--r--. 1 root root  6898 Apr  3 12:06 RELEASE-NOTES
-rw-r--r--. 1 root root 16262 Apr  3 12:06 RUNNING.txt
drwxr-xr-x. 2 root root  4096 Apr 24 23:49 bin
drwxr-xr-x. 3 root root  4096 May 23 08:41 conf
drwxr-xr-x. 2 root root    78 Apr 24 23:49 include
drwxr-xr-x. 2 root root  4096 Apr 24 23:49 lib
drwxrwxrwx. 2 root root  4096 May 23 08:41 logs
drwxr-xr-x. 3 root root  4096 Apr 24 23:49 native-jni-lib
drwxrwxrwx. 2 root root    30 Apr 24 23:49 temp
drwxr-xr-x. 2 root root     6 Apr 24 23:49 webapps
drwxr-xr-x. 7 root root    81 Apr  3 12:04 webapps.dist
drwxrwxrwx. 2 root root     6 Apr  3 12:02 work
root@2cb65acbee53:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@2cb65acbee53:/usr/local/tomcat#

 

最后访问

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值