I have 2 docker containers running on my host, web1 and web2. Container web1 maps port 8080 to the host port 18080, and web2 maps port 8080 to the host port 28080. The IP address of the host is 192.168.20.111 (yes it’s LAN). I can access 192.168.20.111:18080 and 192.168.20.111:28080 from other machines in the same LAN.
When I tried to access 192.168.20.111:18080 (curl 192.168.20.111:18080) or 192.168.20.111:28080 from within web1/web2 container, I got a timeout error.
However, the Apache server running on port 8080 of the host can be accessed by 192.168.20.111:8080 from within web1/web2 container, which means the route from container to host is clear.
So my question is: Why the timeout error happens and how to access 192.168.20.111:18080 from docker container?
This is the docker-compose file I used to start up web2:
version: '2' services: web: build: . ports: - "28080:8080" expose: - "8080" environment: - TALENTS_AUTH_HOST=192.168.20.111 - TALENTS_AUTH_PORT=18080 - TALENTS_ANALYSIS_HOST=192.168.20.111 - TALENTS_ANALYSIS_PORT=18082