cjauvin
cjauvin

Reputation: 3693

Containerization pattern best practice

I am dockerizing a Python webapp using the https://hub.docker.com/r/tiangolo/uwsgi-nginx image, which uses supervisor to control the uWSGI instance.

My app actually requires an additional supervisor-mediated process to run (LibreOffice headless, with which I generate documents through the appy module), and I'm wondering what is the proper pattern to implement it.

The way I see it, I could extend the above image with the extra supervisor config for my needs (along with all the necessary OS-level install steps), but this would be in contradiction with the general principle of running the least amount of distinct processes in a given container. However, since my Python app is designed to talk with LibreOffice only locally, I'm not sure how I could achieve it with a more containerized approach. Thanks for any help or suggestion.

Upvotes: 0

Views: 194

Answers (2)

Elton Stoneman
Elton Stoneman

Reputation: 19154

The recommendation for one-process-per-container is sound - Docker only monitors the process it starts when the container runs, so if you have multiple processes they're not watched by Docker. It's also a better design - you have lightweight, focused containers with single responsibilities, and you can manage them independently.

user2105103 is right though, the image you're using already loses that benefit because it runs Python and Nginx, and you could extend it with LibreOffice headless and package your whole app without changing code.

If you move to a more "best practice" approach, you'd have a distributed app running across three containers in a Docker network:

  • nginx - web proxy, this is the public entry point to the app. Nginx can do routing, caching, SSL termination, rate limiting etc.
  • app - your Python app, only visible inside the Docker network. Receives requests from nginx and uses libreoffice for document manipulation;
  • libreoffice - running in headless mode with the API exposed, but only available within the Docker network.

You'd need code changes for this, bringing in something like PyOO to use the LibreOffice API remotely from the app container.

Upvotes: 2

user2105103
user2105103

Reputation: 13095

You've already blown the "one process per container" -- just add another process. It's not a hard rule, or even one that everybody agrees with.

Extend away, or better yet author your own custom container. That way you own it, you understand it, and it's optimized for your purpose.

Upvotes: 1

Related Questions