[英]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.