Search code examples
dockerdocker-machine

Docker best practises for managing websites


What do you think is best practise for running multiple website on the same machine, would you have separate containers set for each website/domain? Or have all the sites in the one container set?

Website 1, Website 2, Website 3:

  • nginx
  • phpfpm
  • mysql

or

Website 1:

  • nginx_1
  • phpfpm_1
  • mysql_1

Website 2:

  • nginx_2
  • phpfpm_2
  • mysql_2

Website 3:

  • nginx_3
  • phpfpm_3
  • mysql_3

Solution

  • I prefer to use separate containers for the individual websites but use a single webserver as proxy. This allows you to access all websites of different domains on the same host ports (80/443). Additionally you don't necessarily need to run multiple nginx containers.

    Structure:

    • Proxy
      • nginx (listens to port 80/443)
    • Website 1
      • phpfpm_1
      • mysql_1
    • Website 2
      • phpfpm_2
      • mysql_2
    • ...

    You can use automated config-generation for the proxy service such as jwilder/nginx-proxy that also opens the way to use convenient SSL-certification handling with e.g. jrcs/letsencrypt-nginx-proxy-companion.

    The proxy service can then look like this:

    • Proxy
      • nginx (listens to port 80/443)
      • docker-gen (creates an nginx config based on the running containers and services)
      • letsencrypt (creates SSL certificates if needed)