Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Host port mapping not working with docker-compose on EC2

I tried to run this hello world app on an AWS EC2 instance with docker-compose up --build . It works as expected and is accessible remotely from the EC2 public IP when I use port 80 i.e., "80:80" as shown in the docker-compose file.

However, if I change to another port such as "5106:80", it is not accessible from a remote host using <public IPv4 address>:5106 even though it's available locally if I ssh unto the EC2 instance and try localhost:5106. Please note:

  1. I've ensured the EC2 is in a public subnet and I have configured the security group to make the port (in this case, 5106) accept inbound traffic from my laptop.

  2. I know it's not a problem with the hello-world app because I experience exactly the same problem with another app i.e., only port 80 works with docker-compose port mapping on EC2.

like image 701
Kes115 Avatar asked May 01 '19 15:05

Kes115


2 Answers

As it works with port 80 and doesn't work with port 5106 it could mean one of two possibilities:

  • There is an issue with your security groups. You should check you have added port 5106 in your inbound rules of your security group.
  • There is an issue with a firewall or antivirus that doesn't allow you to connect to web pages in different ports rather than 80 or 443. You may try if this happens with another device or on another network.

In this case, it seemed to be the latter.

like image 63
Juan Scolari Avatar answered Nov 19 '22 21:11

Juan Scolari


Possible that the docker network needs to be deleted?

docker network rm $(docker network ls -q)

Then run docker-compose up again.

like image 22
Michael Quale Avatar answered Nov 19 '22 21:11

Michael Quale