skip to Main Content

I have a docker container running a .NET WebAPI. I have configured the container to running using the network mode "host". The reason for this is that I have a MySQL Database running on the same EC2 Instance, but not containerized:

services:
  api:
    image: <<>>
    restart: always
    network_mode: host

I am able to access the service with wget:

Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK

However I am unable to access the same when attempting to connect using my EC2 Instance public endpoint. I have made sure that the EC2 Instance security group is allowing HTTP/HTTPS traffic:

enter image description here

Any suggestions on how to resolve this?

2

Answers


  1. Chosen as BEST ANSWER

    I resolved this by adding an iptables rule to allow traffic on port 80. I've never had to do this but there you go.


  2. You need to check your service is running on 127.0.0.1 or 0.0.0.0. 127.0.0.1 is loopback ip address. You can not access 127.0.0.1 from external. EC2 instances has more than one ip addresses.

    For more details check here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search