5

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?

Josip Ivic
1,6676 gold badges29 silver badges46 bronze badges
asked Mar 14, 2017 at 13:39
5
  • 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}? Commented Mar 14, 2017 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. Commented Mar 14, 2017 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. Commented Mar 14, 2017 at 15:49
  • Docker has a lot of built ins that work for this, have you looked at any of them? Commented Mar 14, 2017 at 19:46
  • I have wondered about this as well. Commented Mar 15, 2017 at 19:30

1 Answer 1

2

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.

answered Mar 14, 2017 at 16:30
1
  • Just a hint for OP, take a look at proxy_pass. Commented Mar 14, 2017 at 21:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.