Docker container cannot connect to host local area network

Source: Internet
Author: User
Keywords Docker php centos
Tags docker run
    1. Create a container with a centos image, deploy a PHP project within a container, and because you want to request an interface service from another server on the local area network, the originating HTTP request is always connected but can be connected to the Internet.

2.
Host ip:172.20.20.152,
The target server for the request interface ip:172.17.3.97

To create a docker container command:
Docker run-p 80:80--name=mycns-it Eeb3a076a0be/bin/bash

After entering the container, execute the command:
Ping 172.17.3.97
The return result is:
From 172.17.0.3 icmp_seq=1 Destination Host Unreachable
From 172.17.0.3 icmp_seq=2 Destination Host Unreachable
From 172.17.0.3 icmp_seq=3 Destination Host Unreachable
From 172.17.0.3 icmp_seq=4 Destination Host Unreachable
From 172.17.0.3 icmp_seq=5 Destination Host Unreachable
From 172.17.0.3 icmp_seq=6 Destination Host Unreachable
From 172.17.0.3 icmp_seq=8 Destination Host Unreachable
From 172.17.0.3 icmp_seq=9 Destination Host Unreachable

To install Docker version information:
Docker version
Return:
Client version:1.7.1
Client API version:1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
Os/arch (client): LINUX/AMD64
Server version:1.7.1
Server API version:1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
Os/arch (server): LINUX/AMD64

3.
The host executes the Ifconfig command and returns:
Docker0 Link encap:ethernet HWaddr ee:25:c5:da:10:47

      inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0      inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:64400 errors:0 dropped:0 overruns:0 frame:0      TX packets:69800 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:3945235 (3.7 MiB)  TX bytes:105962604 (101.0 MiB)

Eth0 Link encap:ethernet HWaddr f2:3d:f0:2b:43:31

      inet addr:172.20.20.152  Bcast:172.20.255.255  Mask:255.255.0.0      inet6 addr: fe80::f03d:f0ff:fe2b:4331/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:29702118 errors:0 dropped:0 overruns:0 frame:0      TX packets:583992 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:1000       RX bytes:2997801386 (2.7 GiB)  TX bytes:73288231 (69.8 MiB)

Lo Link encap:local Loopback

      inet addr:127.0.0.1  Mask:255.0.0.0      inet6 addr: ::1/128 Scope:Host      UP LOOPBACK RUNNING  MTU:65536  Metric:1      RX packets:7059 errors:0 dropped:0 overruns:0 frame:0      TX packets:7059 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:4819120 (4.5 MiB)  TX bytes:4819120 (4.5 MiB)

veth50f5616 Link encap:ethernet HWaddr ee:25:c5:da:10:47

      inet6 addr: fe80::ec25:c5ff:feda:1047/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:17 errors:0 dropped:0 overruns:0 frame:0      TX packets:6 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:1014 (1014.0 b)  TX bytes:468 (468.0 b)

4.
The host can normally connect 172.17.3.97 this machine, but after the Docker service starts, it cannot connect properly.

A great God to help see hehe

Reply content:

    1. Create a container with a centos image, deploy a PHP project within a container, and because you want to request an interface service from another server on the local area network, the originating HTTP request is always connected but can be connected to the Internet.

2.
Host ip:172.20.20.152,
The target server for the request interface ip:172.17.3.97

To create a docker container command:
Docker run-p 80:80--name=mycns-it Eeb3a076a0be/bin/bash

After entering the container, execute the command:
Ping 172.17.3.97
The return result is:
From 172.17.0.3 icmp_seq=1 Destination Host Unreachable
From 172.17.0.3 icmp_seq=2 Destination Host Unreachable
From 172.17.0.3 icmp_seq=3 Destination Host Unreachable
From 172.17.0.3 icmp_seq=4 Destination Host Unreachable
From 172.17.0.3 icmp_seq=5 Destination Host Unreachable
From 172.17.0.3 icmp_seq=6 Destination Host Unreachable
From 172.17.0.3 icmp_seq=8 Destination Host Unreachable
From 172.17.0.3 icmp_seq=9 Destination Host Unreachable

To install Docker version information:
Docker version
Return:
Client version:1.7.1
Client API version:1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
Os/arch (client): LINUX/AMD64
Server version:1.7.1
Server API version:1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
Os/arch (server): LINUX/AMD64

3.
The host executes the Ifconfig command and returns:
Docker0 Link encap:ethernet HWaddr ee:25:c5:da:10:47

      inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0      inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:64400 errors:0 dropped:0 overruns:0 frame:0      TX packets:69800 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:3945235 (3.7 MiB)  TX bytes:105962604 (101.0 MiB)

Eth0 Link encap:ethernet HWaddr f2:3d:f0:2b:43:31

      inet addr:172.20.20.152  Bcast:172.20.255.255  Mask:255.255.0.0      inet6 addr: fe80::f03d:f0ff:fe2b:4331/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:29702118 errors:0 dropped:0 overruns:0 frame:0      TX packets:583992 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:1000       RX bytes:2997801386 (2.7 GiB)  TX bytes:73288231 (69.8 MiB)

Lo Link encap:local Loopback

      inet addr:127.0.0.1  Mask:255.0.0.0      inet6 addr: ::1/128 Scope:Host      UP LOOPBACK RUNNING  MTU:65536  Metric:1      RX packets:7059 errors:0 dropped:0 overruns:0 frame:0      TX packets:7059 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:4819120 (4.5 MiB)  TX bytes:4819120 (4.5 MiB)

veth50f5616 Link encap:ethernet HWaddr ee:25:c5:da:10:47

      inet6 addr: fe80::ec25:c5ff:feda:1047/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:17 errors:0 dropped:0 overruns:0 frame:0      TX packets:6 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:1014 (1014.0 b)  TX bytes:468 (468.0 b)

4.
The host can normally connect 172.17.3.97 this machine, but after the Docker service starts, it cannot connect properly.

A great God to help see hehe

Find out why: http://dev.bidlust.com/?p=103

You can not apply bridging networks, use a host-only network, which is identical to the host, and Docker run adds parameters:--net host

It's supposed to be a firewall.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.