1. Purpose Write a Flask application locally, package it with Docker, upload it to your own server, and complete the deployment. flow chart: 2. Experimental Environment Local: Windows 10 1909 Server: Alibaba Cloud Centos system 3. Required Software 1.Docker Desktop 2. Pycharm 2020.3.3 4. Steps 1. Complete the Flask application locally (1) Create a new Flask application docker_flask in PyCharm (2) Install gunicorn and gevent packages (3) Create a new gunicorn.config.py file and fill in the following content workers = 5 # Define the number of processes that are opened at the same time to handle requests, and adjust appropriately according to the website traffic worker_class = "gevent" # Use the gevent library to support asynchronous processing of requests and improve throughput bind = "0.0.0.0:8080" # Here 8080 can be adjusted at will (4) Create a new requirements.txt file and fill in the following content
(5) Create a Dockerfile file and fill in the following content FROM python:3.7 WORKDIR /usr/src/app COPY requirements.txt ./ RUN pip install -r requirements.txt -i COPY . . CMD ["gunicorn", "app:app", "-c", "./gunicorn.conf.py"] #The first app is the file name started by Python, i.e. app.py; the second one is the pre-started application name in the flask project (6) Project structure 2. Build a Docker image 1. Enter the directory of this project 2. Build the image and enter the following command docker build -t 'docker_flask' . Then six steps will be executed. We don't need to worry about it and just look at the results. Check it out OK, now our self-made image is ready. You can run it locally and experiment with it. 3. Upload the image to Alibaba Cloud Warehouse (1) Create your own Docker repository on Alibaba Cloud. (2) Upload the image 1. Log in to Alibaba Cloud Docker Registry and remember to change your username to your own. docker login --username=your Alibaba Cloud username registry.cn-hangzhou.aliyuncs.com The login password is your Alibaba Cloud login password 2. Enter the following two lines of commands to push the image to the Registry docker tag [image ID] registry.cn-hangzhou.aliyuncs.com/namespace/warehouse name:[image version number] docker push registry.cn-hangzhou.aliyuncs.com/namespace/warehouse name:[image version number] Then don't worry about it, just let it finish running. I uploaded it here before. 4. Pull this image on the server and run it (of course, Docker must be installed on the server first) docker pull registry.cn-hangzhou.aliyuncs.com/namespace/warehouse name:[image version number] Log in to the server via ssh, enter the command above, and then check if it is pulled down. 4. Run it and see if it works Here I map docker's port 8080 to the server's port 28080 OK, enter the server IP: 28080 and see if you can see Hello World! (remember to open the port) This is the end of this article about the implementation steps of Docker deployment of Flask application. For more relevant content about Docker deployment of Flask application, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Vue scroll down to load more data scroll case detailed explanation
>>: Mysql string interception and obtaining data in the specified string
Simple example of adding and removing HTML nodes ...
First, let's introduce several common operati...
Table of contents Nesting Parent-child component ...
Unicode Signature BOM - What is the BOM? BOM is th...
Install SSHPASS For most recent operating systems...
Preview: Code: Page Sections: <template> &l...
Overview The framework diagram of this article is...
1 Check whether the kernel has a tun module modin...
1. addtime() Add the specified number of seconds ...
I recently started learning database, and I feel ...
This article shares the specific code of Vue to a...
This article example shares the specific code of ...
In MySQL, fields of char, varchar, and text types...
Centos7 startup process: 1.post(Power-On-Self-Tes...
There are four main MySQL string interception fun...