Container ports

can i configure all the containers to use same ports but differentiate between them using hostnames or any DNS configuration?

That’s not a configuration option for the docker daemon: each container must expose unique ports to the host.

You could implement the behavior you want with a reverse proxy. You could set up Nginx or some other webserver/reverse proxy and have it listen on a port. When a request comes in, the reverse proxy would forward the request to your container’s unique port based on whatever criteria the proxy supports (hostnames is a common technique and is widely supported). In Nginx, you’d use a server section to separate out requests based on hostname.

1 Like