Answers: <p>While this is possible it is not a best practice.  Whenever possible, containers should contain a single process.  The reasoning for this is:</p>
  
  <ul>
  <li>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 <a href="https://en.wikipedia.org/wiki/Microservices" rel="nofollow noreferrer">microservices</a> for more information on the benefits a modular design.</li>
  <li>It is easier to parse container logs as each container will have its own distinct output.</li>
  <li>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 <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/" rel="nofollow noreferrer">Kubernetes Pod</a> as the Pod can restart.</li>
  </ul>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-19T18:39:07.233Z
Answers: 2019-12-19T18:39:07.233Z
Answers: Wesley Rolnick
Body: <p>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:</p>
  
  <ol>
  <li>flask, gunicorn</li>
  <li>nginx</li>
  </ol>
  
  <p>Is it possible and a good idea to use all three components in just a single docker container?</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-12-19T13:22:44.080Z
Comments: Could you explain why you are using flask, gunicorn and nginx and what you are trying to achieve?
Comments: 030
Comments: CC BY-SA 4.0
Comments: 2019-12-19T13:26:46.417Z
Comments: I want to deploy a web site. This is just a usually web application stack when the backend is written in python.
Comments: tbzk
Comments: CC BY-SA 4.0
Comments: 2019-12-19T13:30:35.907Z
Comments: According to [this blog](https://testdriven.io/blog/dockerizing-flask-with-postgres-gunicorn-and-nginx/) it is acceptable. Please check this blog and document the findings as an answer.
Comments: 030
Comments: CC BY-SA 4.0
Comments: 2019-12-19T13:36:34.713Z
Comments: In my understanding that are multiple containers composed
Comments: tbzk
Comments: CC BY-SA 4.0
Comments: 2019-12-19T13:37:22.027Z
Comments: According the docker-compose.yml in the blog there are two containers, one with postgres and the other one contains the other services.
Comments: 030
Comments: CC BY-SA 4.0
Comments: 2019-12-19T13:39:35.300Z
Comments: at the end there are 3 containers (web, db, nginx)
Comments: tbzk
Tags: <docker><python><nginx><flask>
Title: Is it a bad idea to use a web app including nginx, gunicorn and flask in a single docker container?
UserDisplayName: tbzk
ThreadText: # Is it a bad idea to use a web app including nginx, gunicorn and flask in a single docker container?
  
  (Asked by: username_0 on 2019-12-19)
  
  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?
  
  **Tags:** docker, python, nginx, flask
  
  > **Comments:**
  > **username_1**: Could you explain why you are using flask, gunicorn and nginx and what you are trying to achieve?  
  > **username_0**: I want to deploy a web site. This is just a usually web application stack when the backend is written in python.  
  > **username_1**: According to [this blog](https://testdriven.io/blog/dockerizing-flask-with-postgres-gunicorn-and-nginx/) it is acceptable. Please check this blog and document the findings as an answer.  
  > **username_0**: In my understanding that are multiple containers composed  
  > **username_1**: According the docker-compose.yml in the blog there are two containers, one with postgres and the other one contains the other services.  
  > **username_0**: at the end there are 3 containers (web, db, nginx)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-12-19. Score: 1 | Accepted answer
  
  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](https://en.wikipedia.org/wiki/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](https://kubernetes.io/docs/concepts/workloads/pods/pod/) as the Pod can restart.
  
  
  ---
  
  