Best Practice for Mapping Domain Names to Docker Container

What is considered "best practices" for serving a a docker container from a specific domain name?

For example:

  • Container1 runs App A on port 8080, and accessed via AwesomeAppA.com
  • Container2 runs App B on port 8090, and accessed via AwesomeAppB.com

You can then, for example:

  1. Have your container expose the port used by Gunicorn/uWSGI, for example, and use Nginx on the docker host to handle the proxy.
  2. But you can also have your container run Nginx internally and use HAProxy.

But which is better? Are there other preferred options, or is it really down to personal preference?

Option 1 conforms to the single-responsibility principle, and allows you to run your 1 application in the container and let the host handle the proxy. It also allows Nginx to handle SSL, but requires additional setup and provisioning besides just "docker run".


The Best Practice according to Docker principles is to conform to the single-responsibility principle.

That is option 1 is the preferred way to go.

For the rationale behind this see this interesting article

Beside this you can use Docker in the way you think more suitable for your business needs.