1

I have simple Flask application (simply shows "Hello world"), I would like to deploy it on AWS Elastic BeanStalk. Multiple tutorial show deployment with nginx and gunicorn. 1) I don't understand why we need to use nginx, gunicorn is already a web-server to replace Flask build-in web server. 2) Tutorials show how to build two Docker containers: one for Flask and gunicorn and another for nginx. Why do I need two containers, can I package all in one? With two containers I cannot use Single Container Docker, I need to use Multicontainer Docker.

Any thoughts?

user1700890
  • 7,144
  • 18
  • 87
  • 183

1 Answers1

1

Usually in this trio nginx is used as reverse proxy.

It is possible to package flask+gunicorn+nginx in the same docker container:

For example:

FROM python:3.6.4

# Software version management
ENV NGINX_VERSION=1.13.8-1~jessie
ENV GUNICORN_VERSION=19.7.1
ENV GEVENT_VERSION=1.2.2

# Environment setting
ENV APP_ENVIRONMENT production

# Flask demo application
COPY ./app /app
RUN pip install -r /app/requirements.txt

# System packages installation
RUN echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list
RUN wget https://nginx.org/keys/nginx_signing.key -O - | apt-key add -
RUN apt-get update && apt-get install -y nginx=$NGINX_VERSION 
&& rm -rf /var/lib/apt/lists/*

# Nginx configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/nginx.conf

# Gunicorn installation
RUN pip install gunicorn==$GUNICORN_VERSION gevent==$GEVENT_VERSION

# Gunicorn default configuration
COPY gunicorn.config.py /app/gunicorn.config.py

WORKDIR /app

EXPOSE 80 443

CMD ["nginx", "-g", "daemon off;"]
Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
  • 1
    Thank you so much for reply. I am guessing that in order for everything to work, I need `nginx` config to launch `gunicorn` with `wsgi.py` file as parameter referencing Flask application to run – user1700890 May 16 '19 at 17:12