Docker Community Forums

Share and learn in the Docker community.

Using a mapped port inside a container

Hi, excuse me if my terminology isn’t correct. ( feel free to educate )

Inside a container I have a webserver running on port 80

Lets say that port 80 is mapped to 8080 on the host machine in docker-compose e.g.
- “8080:80”

OK so everything works fine, except the webapp needs to store the base url and use that as required from teh browser on the host, and that code is third party so that is just how it works
i.e. http://localhost:8080

When the web app decides to make an API call to itself it then tries on localhost:8080, but as the code is running inside the container - it gets refused, as inside the container it should communicate on port 80.

Given the code is fixed, the solution to me would be to configure inside the container to open port 8080 and reverse map it back to 80.

Is there a ‘docker’ way of achieving this?

I’m thinking otherwise then it might be a casse of configuring iptables in docker, but I’m not so experienced with iptables to full work out what is required.