<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>

CC BY-SA 4.0
2019-12-19T18:39:07.233Z
2019-12-19T18:39:07.233Z
Wesley Rolnick
<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>

CC BY-SA 4.0
2019-12-19T13:22:44.080Z
Could you explain why you are using flask, gunicorn and nginx and what you are trying to achieve?
030
CC BY-SA 4.0
2019-12-19T13:26:46.417Z
I want to deploy a web site. This is just a usually web application stack when the backend is written in python.
tbzk
CC BY-SA 4.0
2019-12-19T13:30:35.907Z
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.
030
CC BY-SA 4.0
2019-12-19T13:36:34.713Z
In my understanding that are multiple containers composed
tbzk
CC BY-SA 4.0
2019-12-19T13:37:22.027Z
According the docker-compose.yml in the blog there are two containers, one with postgres and the other one contains the other services.
030
CC BY-SA 4.0
2019-12-19T13:39:35.300Z
at the end there are 3 containers (web, db, nginx)
tbzk
<docker><python><nginx><flask>
Is it a bad idea to use a web app including nginx, gunicorn and flask in a single docker container?
tbzk
# 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.


---

