3

So currently I have an Python Flask application. It is a basic script with different webhooks. For each new webhook I want to add I would need a different Docker container. So since I will be expanding the webhooks I must(?) use docker to setup multiple containers. But when I try to create different endpoints with a Dockerfile, I would have to create manually some endpoints in the nginx.conf and different sockets for uwsgi (or build a script which does all the sockets, endpoints etc.).

So what I basically want to achieve is:

Example.com/webhook1 (container1)
Example.com/webhook2 (container2)
Example.com/webhook3 (container3)
etc.

What would be my best approach to have different containers running with different endpoints?

My server is a Ubuntu server using NGINX as a reverse proxy with uwsgi, and certbot for the ssl cert.

1 Answer 1

1

There are multiple approaches to achieve this.

What I did was that I created a so called "master" NGINX container (or it can run on the host too) which communicates via port 443. Then I have set up all other container to use a different port (or you can also use UNIX Sockets). Then I've set up my "master" NGINX instance as a reverse proxy.

For example, lets see the following setup of NGINX instances:

In the master NGINX instance's config, you should have something like this:

location /webhook1 {
  proxy_pass       http://127.0.0.1:8801/webhook1;
}

location /webhook2 {
  proxy_pass       http://127.0.0.1:8802/webhook2;
}

You only have to use SSL on your "main" NGINX instance, as it's unnecessary when communicating on the same machine. Just make sure that your firewall denies access to all other internal NGINX instances.

3
  • for most part, this is the approach I took with another container platform (LXD) - though in that case, the containers, other than the web one can't talk directly to the outside world and all certs, domain names and vhosts are managed in one place
    – Journeyman Geek
    Commented Aug 28, 2021 at 14:50
  • That is a great idea! Wouldn't I need to edit the config with every new docker container though?
    – Danny O
    Commented Aug 28, 2021 at 17:21
  • Yes, you have to. If you don't want to bother with it every time you start a new container, you can either pre-configure a lot of ports (easy, but hacky), or you could write a script to automatically update your configuration, however, that's a bit more complicated.
    – smart123s
    Commented Aug 29, 2021 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .