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?

  • I think a little more detail is needed. It sounds like your composed application listens on port 80, and you'd like to run multiple instances of it on the same host. How would you do it if you wanted to run multiple ${other_web_application}? – FrustratedWithFormsDesigner Mar 14 '17 at 14:59
  • Yes, exactly. So far, I have been running multiple applications by manually creating nginx config files, that connect the domain to the app, but I figured that there's gotta be a more elegant solution with docker. Spinning up the containers and then manually adding nginx config doesn't seem right. And specifying the settings inside of the container doesn't seem right either. There's gotta be a procedural way to do this, that allows anyone to spin up a bunch of instances of the blog on their server, and server them automatically. – Ray Alez Mar 14 '17 at 15:04
  • It's possible to use Ansible to manage docker containers, but it might be overkill for this situation, I'm not sure. A simple script that manages nginx and the config might be easier. – FrustratedWithFormsDesigner Mar 14 '17 at 15:49
  • Docker has a lot of built ins that work for this, have you looked at any of them? – enderland Mar 14 '17 at 19:46
  • I have wondered about this as well. – wogsland Mar 15 '17 at 19:30

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.

  • Just a hint for OP, take a look at proxy_pass. – RubberDuck Mar 14 '17 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.