Deploy the environment Ubuntu

Use the tools Gunicorn + Gevent + Flask + docker + Pycharm

All operations are performed in Ubuntu (Gunicorn + Gevent does not support a WIN environment!)

So let’s start with a Flask project (Python)

Encapsulation with Blueprint/Show Down {}

Open the run.py file

Use Gunicorn + Gevent to start the flask project

pip install gunicorn gevent

I had this problem during the installation

Sudo apt-get install python3.6-dev sudo apt-get install python3.6-dev

When the download is complete, you can use the command to start the flask project

Gunicorn -W 4-B 192.168.1.79:4000 Run :app

-W 4 refers to the number of predefined worker processes in 4 -B 192.168.1.79:4000 refers to the binding address IP and port Run is Flask's startup Python file, and APP is Flask's application instance

This proves that Gunicorn gevent is available!!

Next, we use Docker to encapsulate the project into mirroring

First, the file directory will be there

Requirements. TXT file – the package name applied to the project write to gunicorn.conf.py file – the command step to define the gevent library and the number of processes Dockerfile – the docker package image

Requirements. TXT file

You can use the command to write the application package Pip Freeze > requires.txt for your project

Gunicorn. Conf. Py files
Worker_class = "gevent" # Worker_class = "gevent" # Worker_class = "gevent" # Support asynchronous processing of requests Improve throughput bind = "0.0.0.0:8080" # 8080 can be adjusted freely here

Dockerfile file
WORKDIR /usr/ SRC /app RUN PIP install --upgrade PIP COPY requirements.txt./ RUN PIP install -r requirements.txt COPY . . CMD ["gunicorn", "run:app", "-c", "./gunicorn.conf.py"]

The following commands are executed in root mode

Su root – Enter the native password

Find the CMD path of the project and do Docker packaging to generate the image

Enter the command:

docker build -t 'docker_flask' .

It can be a very long process… (Depending on the size of your project environment package)

When you see this, you’re done packing

The next step is to enable the flask project using Docker

View the packaged image

docker images

Use the command to start mirroring (8088 can be mapped to prevent 8080 port usage) docker run-itd-p 8088:8080 docker_flask

-i interactive operation -t terminal -d background operation

See the Docker container in action

docker ps

The container is open. You can test using native IP + 8088

Remember to open port 8088 – you can debug with the network segment.



And you’re done!