Forward DNS to specific ports to access docker container

dockerdomain-name-system

I have 1 domain and 1 subdomain:

example.com.au
api.example.com.au

I have 2 docker containers running 2 different applications, a frontend website and an API. These containers are accessible over 8080 (frontend) and 3000 (backend).

Both domains are on an ELB over HTTPS and I have setup IP routing to forward traffic from http and https to port 8080 so the frontend web app is loading fine but the webapp needs to access the API through a different domain (subdomain) however I am completely lost on how to get api.example.com.au to load data from the API on port 3000.

I thought perhaps an apache container accepting all traffic from example.com.au and api.example.com.au and then proxypass to the appropriate containers over the different ports but also unsure how to achieve this based on some examples I found…or even if this is the best approach.

Best Answer

DNS only provides name to IP lookup, this has nothing to do with ports.

What you should probably be looking at is how vhosts work in a webserver, after that you can use reverse proxy functionality. or HTTP redirects to give url with different port (I do not recommend you doing this)

But the main take away here is again that DNS can never be used to control ports or parts of the url other then just which IP a given hostname should connect to.