Docker containers serving different subdomains on port 80

Viewed 2742

Is it possible to have a 2 docker containers serve on port 80 but different subdomains or hostnames?

Something like:

api.example.com goes to a node application

app.example.com goes to a Java application

2 Answers

No. The first container you start will have exclusive access to the port, and if you try and start a second container on the same port it will fail.

Instead, use a load balancer such as Nginx or Traefik to handle the incoming traffic to port 80 and proxy it on to your two app containers based on host headers.

Related