Understanding Docker overlay network

332 Views Asked by At

I am using an overlay network to deploy an application on multiple VMs on the same LAN. I am using nginx as the front end for this application and this is running on host_1. All the containers that are part of the application are communicating with each other without any issues. But HTTP requests to the published port 80 of the nginx container (mapped to port 8080 on host_1) from a different VM on the same LAN, say host_2, time out[1]. But HTTP requests to localhost:8080 on host_1 succeed[2]. If I start the nginx container by removing the overlay network, I am able to send HTTP requests[3].

  1. Output of curl -vvv <host_1 IP>:8080 on host_2.

ubuntu@host_2:~$ curl -vvv <host_1>:8080

  • Rebuilt URL to: <host_1 IP>:8080/
  • Trying <host_1 IP>...
  • TCP_NODELAY set
  • connect to <host_1 IP> port 8080 failed: Connection timed out
  • Failed to connect to <host_1 IP> port 8080: Connection timed out
  • Closing connection 0 curl: (7) Failed to connect to <host_1 IP> port 8080: Connection timed out
  1. Output of curl localhost:8080 on host_1.

nginx welcome page

  1. Output of curl -vvv <host_1 IP>:8080 on host_2 when I recreate the container without the overlay network

nginx welcome page

The docker-compose file for the front end is as below:

version: '3'
  nginx-frontend:
    hostname: nginx-frontend
    image: nginx
    ports: ['8080:80']
    restart: always
networks:
  default:
    external: {name: overlay-network}

I checked that the nginx and the host are listening on 0.0.0.0:80 and 0.0.0.0:8080 respectively.

Since the port 80 of the nginx is published by mapping it to port 8080 of the host, I should be able to send HTTP requests from any VM that is on the same LAN as the host of this container. Can someone please explain what I am doing wrong or where my assumptions are wrong?

0

There are 0 best solutions below