简体   繁体   English

我已经在centos 7中安装了docker容器,但是docker容器和主机不在同一网络上,这就是为什么docker无法从外部访问的原因?

[英]i have installed docker container in centos 7 but docker container and host are not on same network thats why docker is not accessible from outside?

在此处输入图片说明

1.eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:81:92:a4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.92.134/24 brd 192.168.92.255 scope global dynamic eno16777736
       valid_lft 1128sec preferred_lft 1128sec
    inet6 fe80::20c:29ff:fe81:92a4/64 scope link 
       valid_lft forever preferred_lft forever
2.: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN 
    link/ether 02:42:a7:60:5e:c6 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:a7ff:fe60:5ec6/64 scope link 
       valid_lft forever preferred_lft forever

If you want the container and the host to share the same network you need to create the container with the --net=host parameter. 如果希望容器和主机共享同一网络,则需要使用--net=host参数创建容器。

docker run -ti --net=host ubuntu:16.04

By using that command any service you host in that container will be accessible on the host and the network without any additional configuration, assuming that you already don't have another service running on the same port and/or firewall enabled. 通过使用该命令,假定您已经在同一端口和/或防火墙上没有运行其他服务,则无需任何其他配置即可在主机和网络上访问您在该容器中承载的任何服务。

Now, if you want the container to be own its on network but be able to access the hosted service on the host, then you should map a port by using the -p parameter. 现在,如果您希望容器在网络上拥有所有权,但能够访问主机上的托管服务,则应该使用-p参数映射端口。

docker run -p 80:80 apache:latest #Assuming you want to access a webserver for example

You should read more about this on Docker's documentation 您应该在Docker的文档中阅读有关此内容的更多信息。

https://docs.docker.com/engine/userguide/networking/ https://docs.docker.com/engine/userguide/networking/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CentOS 7 上的 Docker 容器内没有网络访问 - No network access from within Docker container on CentOS 7 如何从同一网络中的 docker 容器中扫描 docker 容器 IP? - How to scan docker containers IPs from a docker container that is in the same network? 在带有线保护的 docker 容器中时,为什么我只能从 docker 主机访问 nginx 而不能远程访问? - When in a docker container with wireguard, why can I only access nginx from the docker host and not remotely? 我可以在与要运行diff的容器相同的主机上运行docker diff吗? - Can I run docker diff from a container on the same host as the container I want to run the diff on? 无法从同一局域网中的另一台主机ping Docker容器 - Can not ping docker container from another host which is in the same LAN 如何让主机和容器使用 Docker 读/写相同的文件? - How can I have a host and container read/write the same files with Docker? 无法从主机ping docker容器 - Cannot ping docker container from the host machine 从 docker 容器创建/触摸主机上的文件 - Create/Touch a file on host from docker container Docker:从同一主机中的另一个容器访问 mysql 容器(无路由到主机错误) - Docker: Accessing to a mysql container from another container in same host (No route to host error) 无法将文件从Docker容器复制到主机 - Not able to copy file from docker container to host
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM