Question

I have built a blogging application, running in several containers that are managed with docker-compose.

Now I'm wondering - how does one run multiple instances of such application on one server?

I'm thinking about two scenarios:

  1. What is the right way to connect my project to the port 80, so I could run it along with the other websites I'm hosting on that server. I would like to do that automatically, without the need to modify container settings.

  2. What is the right/elegant way to run hundreds of instances of the project, one for every user? Like if I would want to build something like Ghost. Does anyone know how they are doing it? Or do they just have one common database?

Was it helpful?

Solution

If you are simply looking to load-balance a stateless application across multiple containers, you can use a reverse-proxy such as NGINX to listen on port 80 and distribute requests to the containers which are running in the docker engine. This seems to be a fairly common configuration based on articles and presentations that I've seen.

If you have a fixed number of instances, you can specify the port you want each container to listen on when you start using the -P switch instead of letting the engine pick one at random.

If this is more dynamic or you want to redirect based on paths, you can update the NGINX config on the fly. I'm guessing you aren't the first person that wanted to do this and there are likely tools that implement some sort of management around this.

Licensed under: CC-BY-SA with attribution
scroll top