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
Without relying on JavaScript, pure CSS is used t...
Because I have a database tutorial based on SQL S...
Copy the following code to the code area of Drea...
Table of contents 1. Introduction 2. Simple defin...
External Access Randomly map ports Using the -P f...
Table of contents 1. What is a component? 2. Crea...
This article shares a digital clock effect implem...
I see many novice students doing front-end develop...
question I encountered a problem when writing dat...
1. SSH remote management SSH Definition SSH (Secu...
Table of contents Install and configure dnsmasq I...
Mysql join query 1. Basic concepts Connect each r...
Table of contents 1. Basics 2. Nodes, trees, and ...
Setting up remote access in mysql5.7 is not like ...
Vue+js realizes the fade in and fade out of the v...