I want to deploy a web app as a docker container. Currently I need to set up nginx, gunicorn and flask to realize this. There are many guides around to do it in docker but always divide it in two docker containers:

  1. flask, gunicorn
  2. nginx

Is it possible and a good idea to use all three components in just a single docker container?

  • Could you explain why you are using flask, gunicorn and nginx and what you are trying to achieve?
    – 030
    Dec 19, 2019 at 13:22
  • I want to deploy a web site. This is just a usually web application stack when the backend is written in python.
    – tbzk
    Dec 19, 2019 at 13:26
  • According to this blog it is acceptable. Please check this blog and document the findings as an answer.
    – 030
    Dec 19, 2019 at 13:30
  • In my understanding that are multiple containers composed
    – tbzk
    Dec 19, 2019 at 13:36
  • According the docker-compose.yml in the blog there are two containers, one with postgres and the other one contains the other services.
    – 030
    Dec 19, 2019 at 13:37

1 Answer 1


While this is possible it is not a best practice. Whenever possible, containers should contain a single process. The reasoning for this is:

  • It fosters a modular design where you can more easily plug and play components. What if you decide not to use nginx and use asp.net core in the future? If everything is tightly coupled in one container then the entire container will need to be reworked any time one of these components changes. Look into microservices for more information on the benefits a modular design.
  • It is easier to parse container logs as each container will have its own distinct output.
  • If a process crashes and everything is in one container, the entire container will crash. If you have them broken out across multiple containers, recovery is simplified. While this may not be applicable for running standalone containers, it is very useful if the containers are running in a Kubernetes Pod as the Pod can restart.

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