Home > Software engineering >  Docker service is accessible from EC2 Instance (localhost) but not remotely
Docker service is accessible from EC2 Instance (localhost) but not remotely

Time:01-16

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?

CodePudding user response:

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

CodePudding user response:

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.

  • Related