使docker可以在LAN中访问

时间:2017-10-25 13:01:58

标签: docker

不知怎的,containers_id已经改变,我不知道如何在这个桥上添加一个容器,使得在Docker中运行的项目可用于我们的局域网。

以下是我正在运行的容器: enter image description here

这是我的网络ls: enter image description here

我正在阅读所有这些tuto但是害怕搞砸事情,有人可以帮助我在192.168.0.10中提供这个项目吗?

[UPDATE1]:netstat -tulpn的输出

netstat -tulpn
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::3306                 :::*                    LISTEN      -                   
tcp6       0      0 :::80                   :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      -                   
tcp6       0      0 :::443                  :::*                    LISTEN      -                   
udp        0      0 172.18.0.1:123          0.0.0.0:*                           -                   
udp        0      0 192.168.0.10:123        0.0.0.0:*                           -                   
udp        0      0 127.0.0.1:123           0.0.0.0:*                           -                   
udp        0      0 0.0.0.0:123             0.0.0.0:*                           -                   
udp        0      0 0.0.0.0:4400            0.0.0.0:*                           -                   
udp        0      0 0.0.0.0:49884           0.0.0.0:*                           -                   
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -                   
udp6       0      0 :::14324                :::*                                -                   
udp6       0      0 fe80::34cc:82ff:fec:123 :::*                                -                   
udp6       0      0 fe80::5036:49ff:fec:123 :::*                                -                   
udp6       0      0 fe80::8029:1ff:fe0e:123 :::*                                -                   
udp6       0      0 fe80::1892:d2ff:fe0:123 :::*                                -                   
udp6       0      0 fe80::42:d1ff:fed3::123 :::*                                -                   
udp6       0      0 2804:14d:c680:1b71::123 :::*                                -                   
udp6       0      0 2804:14d:c680:1b71::123 :::*                                -                   
udp6       0      0 fe80::86c2:2e62:9e5:123 :::*                                -                   
udp6       0      0 ::1:123                 :::*                                -                   
udp6       0      0 :::123                  :::*                                -                   
udp6       0      0 fe80::86c2:2e62:9e5:546 :::*                                -                   
udp6       0      0 :::58147                :::*                                -                   
udp6       0      0 :::5353                 :::*     

UPDATE2:docker_agil1_1上的docker inspect

sudo docker inspect --format '{{json .NetworkSettings}}' docker_agil1_1
{"Bridge":"","SandboxID":"b37a7a73bf05cb215796a8b5c34ca9a1c9c2f332f3e865f974980ac5fd034bf2","HairpinMode":false,"LinkLocalIPv6Address":"","LinkLocalIPv6PrefixLen":0,"Ports":{"443/tcp":[{"HostIp":"0.0.0.0","HostPort":"443"}],"80/tcp":[{"HostIp":"0.0.0.0","HostPort":"80"}]},"SandboxKey":"/var/run/docker/netns/b37a7a73bf05","SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null,"EndpointID":"","Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","MacAddress":"","Networks":{"docker_default":{"IPAMConfig":null,"Links":["docker_agil1_db_1:agil1_db_1","docker_agil1_db_1:docker_agil1_db_1","docker_agil1_db_1:mysql"],"Aliases":["e1b469ab4d66","agil1"],"NetworkID":"2889780f55a072444137855fb6c94c4df53d62f0ec51d5b09d42ec8e8d0eb372","EndpointID":"59bb683bd3a81c620492ed7ddea811d7919bbaa08a738249b6ec60e6f50f5043","Gateway":"172.18.0.1","IPAddress":"172.18.0.3","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:12:00:03","DriverOpts":null}}}

UPDATE3: docker network inspect docker_default:

 [
    {
        "Name": "docker_default",
        "Id": "2889780f55a072444137855fb6c94c4df53d62f0ec51d5b09d42ec8e8d0eb372",
        "Created": "2017-08-24T12:00:28.615469234-03:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "17753e89370d03571efe42994b9e1b7300787d05132b6577721792eb1c68446a": {
                "Name": "docker_agilapi_db_1",
                "EndpointID": "5766d902a9447147a583795eafc23175509ee2696a001419b7fa1c9a3881ed74",
                "MacAddress": "02:42:ac:12:00:04",
                "IPv4Address": "172.18.0.4/16",
                "IPv6Address": ""
            },
            "991880fa4093461f902fae7239cfe138f25eacc152687d673e109bbd0cee2f56": {
                "Name": "docker_agil1_db_1",
                "EndpointID": "61b2d06c62a821a25e44a85042509ecd7d58d8dbd4228b60372d181d48b6a55e",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "a75bbb07436930652c2024bee20b426c1d67e95472ee4f635da57fd8370f8431": {
                "Name": "docker_agilapi_1",
                "EndpointID": "51fb0cdb402cd0a9aec9c97accd4028140d92509923d3023bd652a2de5d2d203",
                "MacAddress": "02:42:ac:12:00:05",
                "IPv4Address": "172.18.0.5/16",
                "IPv6Address": ""
            },
            "e1b469ab4d663e2575232bfee06ef52d01c0178946e3e174b64ba2d316a3051d": {
                "Name": "docker_agil1_1",
                "EndpointID": "59bb683bd3a81c620492ed7ddea811d7919bbaa08a738249b6ec60e6f50f5043",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

sudo brctl show:

 bridge name    bridge id       STP enabled interfaces
 br-2889780f55a0        8000.0242d1d3851d   no      veth081c0e3
                            veth342b2da
                            veth34fb985
                            vethe0daeb5 docker0     8000.02427e7776a8   no

Ifconfig -a:

 br-2889780f55a0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 172.18.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
         inet6 fe80::42:d1ff:fed3:851d  prefixlen 64  scopeid 0x20<link>
         ether 02:42:d1:d3:85:1d  txqueuelen 0  (Ethernet)
         RX packets 43  bytes 1468 (1.4 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 78  bytes 6534 (6.3 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
         inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
         ether 02:42:7e:77:76:a8  txqueuelen 0  (Ethernet)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 0  bytes 0 (0.0 B)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 192.168.0.10  netmask 255.252.0.0  broadcast 192.171.255.255
         inet6 2804:14d:c680:1b71::6  prefixlen 128  scopeid 0x0<global>
         inet6 2804:14d:c680:1b71:1611:48cb:a555:faea  prefixlen 64  scopeid 0x0<global>
         inet6 fe80::86c2:2e62:9e56:6694  prefixlen 64  scopeid 0x20<link>
         ether 00:22:15:bd:5d:42  txqueuelen 1000  (Ethernet)
         RX packets 5356  bytes 519236 (507.0 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 2461  bytes 313106 (305.7 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 2  collisions 0
         device memory 0xdffc0000-e0000000  

 lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
         inet 127.0.0.1  netmask 255.0.0.0
         inet6 ::1  prefixlen 128  scopeid 0x10<host>
         loop  txqueuelen 1  (Local Loopback)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 0  bytes 0 (0.0 B)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 veth081c0e3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet6 fe80::34cc:82ff:fec3:7982  prefixlen 64  scopeid 0x20<link>
         ether 36:cc:82:c3:79:82  txqueuelen 0  (Ethernet)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 36  bytes 3418 (3.3 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 veth342b2da: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet6 fe80::1892:d2ff:fe0d:f80b  prefixlen 64  scopeid 0x20<link>
         ether 1a:92:d2:0d:f8:0b  txqueuelen 0  (Ethernet)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 38  bytes 3638 (3.5 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 veth34fb985: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet6 fe80::8029:1ff:fe0e:bdba  prefixlen 64  scopeid 0x20<link>
         ether 82:29:01:0e:bd:ba  txqueuelen 0  (Ethernet)
         RX packets 30  bytes 1440 (1.4 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 57  bytes 4452 (4.3 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 vethe0daeb5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet6 fe80::5036:49ff:fec6:e6b1  prefixlen 64  scopeid 0x20<link>
         ether 52:36:49:c6:e6:b1  txqueuelen 0  (Ethernet)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 35  bytes 3348 (3.2 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

iptables --list

 Chain INPUT (policy ACCEPT) target     prot opt source              
 destination         

 Chain FORWARD (policy DROP) target     prot opt source              
 destination          DOCKER-USER  all  --  anywhere            
 anywhere             DOCKER-ISOLATION  all  --  anywhere            
 anywhere             ACCEPT     all  --  anywhere             anywhere
 ctstate RELATED,ESTABLISHED DOCKER     all  --  anywhere            
 anywhere             ACCEPT     all  --  anywhere             anywhere
 ACCEPT     all  --  anywhere             anywhere             ACCEPT  
 all  --  anywhere             anywhere             ctstate
 RELATED,ESTABLISHED DOCKER     all  --  anywhere             anywhere 
 ACCEPT     all  --  anywhere             anywhere             ACCEPT  
 all  --  anywhere             anywhere            

 Chain OUTPUT (policy ACCEPT) target     prot opt source              
 destination         

 Chain DOCKER (2 references) target     prot opt source              
 destination          
 ACCEPT     tcp  --  anywhere             172.18.0.2           tcp dpt:mysql
 ACCEPT     tcp  --  anywhere             172.18.0.3           tcp dpt:https
 ACCEPT     tcp  --  anywhere             172.18.0.3           tcp dpt:http

 Chain DOCKER-ISOLATION (1 references) target     prot opt source      
 destination          DROP       all  --  anywhere             anywhere
 DROP       all  --  anywhere             anywhere             RETURN  
 all  --  anywhere             anywhere            

 Chain DOCKER-USER (1 references) target     prot opt source           
 destination          RETURN     all  --  anywhere             anywhere

Update4:docker exec

 > sudo docker exec e1b469ab4d66 bash -c "tail -f /var/log/httpd/*"
 ==> /var/log/httpd/access.log <==

 ==> /var/log/httpd/access_log <==

 ==> /var/log/httpd/error.log <== [Mon Oct 02 17:22:32.987017 2017] [ssl:warn] [pid 17] AH01909: RSA certificate configured for
 172.18.0.3:443 does NOT include an ID which matches the server name [Mon Oct 02 17:22:33.073314 2017] [ssl:warn] [pid 17] AH01909: RSA
 certificate configured for 172.18.0.3:443 does NOT include an ID which
 matches the server name

 ==> /var/log/httpd/error_log <== [Mon Oct 02 17:22:32.983193 2017] [suexec:notice] [pid 17] AH01232: suEXEC mechanism enabled (wrapper:
 /usr/sbin/suexec) [Mon Oct 02 17:22:33.068405 2017] [core:warn] [pid
 17] AH00117: Ignoring deprecated use of DefaultType in line 99 of
 /etc/httpd/conf/httpd.conf. AH00558: httpd: Could not reliably
 determine the server's fully qualified domain name, using 172.18.0.3.
 Set the 'ServerName' directive globally to suppress this message [Mon
 Oct 02 17:22:33.070143 2017] [auth_digest:notice] [pid 17] AH01757:
 generating secret for digest authentication ... [Mon Oct 02
 17:22:33.071655 2017] [lbmethod_heartbeat:notice] [pid 17] AH02282: No
 slotmem from mod_heartmonitor [Mon Oct 02 17:22:33.072342 2017]
 [ssl:warn] [pid 17] AH01873: Init: Session Cache is not configured
 [hint: SSLSessionCache] [Mon Oct 02 17:22:34.107773 2017]
 [mpm_prefork:notice] [pid 17] AH00163: Apache/2.4.6 (CentOS)
 OpenSSL/1.0.1e-fips PHP/7.0.22 configured -- resuming normal
 operations [Mon Oct 02 17:22:34.109284 2017] [core:notice] [pid 17]
 AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

2 个答案:

答案 0 :(得分:0)

所以目前你可以通过端口80和443从你的局域网访问docker_agil_1,在端口3306上访问docker_agil1_db_1。当然,所有这些都在你的docker-host的ip上。

要从外部使容器可用,您需要使用-p [HostPort]:[ContainerPort]标志启动容器,就像前面提到的容器一样。

容器会自动添加到“网桥”网络中。如果您想更改它,请使用docker network connect将容器连接到其他网络,或者在启动容器时使用--net [Network]标志。

有用的link关于-p

有用的link关于--net

有用link有关docker network(命令)的信息

一般有关码头工人网络的有用link

答案 1 :(得分:0)

解决方案是: 1-停止并删除所有泊坞容器; 2- sudo docker-在两个docker文件夹上组成-d;

当然,我丢失了docker container_db中的所有数据库,但它比花费4小时试图找到解决方案要好得多,因为它可以通过sql转储文件轻松恢复。

特别感谢所有帮助过的人。感谢efford。