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#

 

最后访问

 

 

 

 

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐