Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

Time:2021-1-25

Deployment environment Ubuntu

Using tools gunicorn + gevent + Flag + docker + pychar

All operations are performed in Ubuntu (gunicorn + gevent does not support win environment!)

First, there is a flash project (Python)

Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

Using blueprint to encapsulate / display {}

Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

open run.py file

Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

Starting flash project with gunicorn + gevent

pip install gunicorn gevent

I had this problem during the installation

Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

You can enter the following command
sudo apt-get install python3.6-dev

After downloading, you can use the command to start the flash project

gunicorn -w 4 -b 192.168.1.79:4000 run:app
Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

-W4 is the predefined number of work processes, which is 4
-B 192.168.1.79:4000 refers to the binding address IP and port
Run is the startup Python file of flash, and app is the instance of flash application

Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

This proves that gunicorn gevent can be used!!

Next, we use docker to encapsulate the project into an image

First, the file directory will have

requirements.txt File – the package name to which the project applies
gunicorn.conf.py File – defines the number of gevent libraries and processes
Dockerfile – command steps for docker packaging image

Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

requirements.txt file

You can use the command to write the application package needed by the project
pip freeze > requirements.txt

gunicorn.conf.py file
Workers = 5 # define the number of processes that can be opened at the same time to process requests, and adjust it appropriately according to the website traffic
worker_ Class = "gevent" # gevent library is adopted to support asynchronous request processing and improve throughput
Bind = "0.0.0.0:8080" # here 8080 can be adjusted at will

Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

Dockerfile file
FROM python:3.6
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"]

Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

Enter the root permission — the following are all commands executed in root mode

su root-Enter the local password

Find the CMD path of the project, pack the docker and generate the image

Input command:
docker build -t 'docker_flask' .
Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

The process can be very long(depending on how many environmental packages you have)

Seeing this proves that the packaging is complete
Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

The next step is to use docker to enable the flash project

View packaged images
docker images
Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

Use the command to start the image
(in order to prevent the occupation of 8080 port, 8088 can be used for mapping)
docker run -itd -p 8088:8080 docker_flask

-I interactive operation
-T terminal
-D background operation

View the running docker container
docker ps
Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

The container has been opened. You can use local IP + 8088 for testing
Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)

Remember to open port 8088 – you can debug with the network segment.
Deploying flash project Ubuntu environment with gunicorn + gevent (docker packaged)
be accomplished!

Recommended Today

020_CSS3

catalog How to learn CSS What is CSS History of development quick get start Advantages of CSS Three ways to import CSS Expansion: two ways of writing external style selector Basic selector Hierarchy selector Structure pseudo class selector attribute selectors Beautify web page elements Why beautify web pages Span label: for the text that needs […]