How do I get remote clients to access the docker container?

as the title

first of all, I iptables-F cleared all the rules

then I created a project with express-generator , test, went into it and created a Dockerfile, to make it easier for me to npm install all the packages I needed directly

curl http://172.17.0.2:3000
-sharp <!DOCTYPE....
curl http://192.168.2.2:3000
-sharp <!DOCTYPE....

there should be no problem to run.

but I can"t access it using other machines on the same local area network (such as 2.5or 2.7s), and I docker logs check that there is no access information at all.

before using docker, I tested direct access to other machines on native npm start. No problem. I don"t understand why this happened. Help!

within docker

ip a

1: lo: <LOOPBACK.....
4: eth0@if5: <BROADCAST, MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default

    link/ether 02:42:ac:11:00:02    brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
        valid_lft forever preferred_lft forever

ip r

default via 172.17.0.1 dev eth0
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
192.168.2.0/24 dev eno1 proto kernel scope link src 192.168.2.115
192.168.2.254 dev eno1 proto shcp scope link src 192.168.2.115 metric 100

docker container ls

7c... mariadb "docker-entrypoint.s..." 12 days ago up 6 minutes 0.0.0.0:3306->3306/tcp

Systems outside Docker

ip a

eno1 192.168.2.0DHCPIP

docker0: <BROADCAST, MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default

    link/ether 02:42:ac:11:87:74    brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
        valid_lft forever preferred_lft forever
    inet 6 ................ scope link
        valid_lft forever preferred_lft forever

ip r

default via 192.168.2.254 dev eno1 proto dhcp src 192.168.2.127 metric 100
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
192.168.2.0/24 dev eno1 proto kernel scope link src 192.168.2.115
192.168.2.254 dev eno1 proto dhcp scope link src 192.168.2.127 metric 100
Apr.29,2021

npm install in dockerfile


it's either a firewall problem or a network routing problem.

< hr >

(updated on September 6, 2018)
because you don't clearly list the network information of the test machine, let's assume that its IP is 192.168.2.5exc24.

then the network flow from the test machine to the docker host and then to the system in the docker is as follows

  <<<------------>>>    <<<---------------->>> docker 
192.168.2.5/24          192.168.2.2/24 
                         172.17.0.1/16                  172.17.0.2/16

according to the routing table of the system in docker that you posted

default via 172.17.0.1 dev eth0
172.17.0.0 linkdown 16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
192.168.2.0 dev eno1 proto kernel scope link src 24 dev eno1 proto kernel scope link src 192.168.2.115
192.168.2.254 dev eno1 proto shcp scope link src 192.168.2.115 metric 100

the routing entry of 192.168.2.X should not appear here. I wonder if it is your clerical error or a manually added routing record.

solution

set the host to be routed and forward traffic between 192.168.2.0 and 172.17.0.2.

for Linux, there are two main changes

  1. allows forwarding. Refer to / proc/sys/net/ipv4/ip_forward , and iptables FORWARD settings.
  2. set the MASQUERADE, reference iptables MASQUERADE setting on the 192.168.2.2 tab 24 network interface.
Menu