简体   繁体   中英

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM