部署flask到带有uwsgi的Docker中

文章目录

    • 1. flask代码
    • 2. uwsgi配置
    • 3. Dockerfile
    • 4. docker-compose
    • 5. 运行

1. flask代码

vim flaskr.py

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "hello world"

2. uwsgi配置

vim wsgi.ini

[uwsgi]
wsgi-file=flaskr.py
callable=app
http=0.0.0.0:5000
master=true

3. Dockerfile

vim Dockerfile

FROM python3
COPY . /

WORKDIR /

ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8

RUN set -eux; \
    mkdir run; \
    apt update; \
    apt install -y gcc python3-dev; \
    pip3 install wheel uwsgi flask;

EXPOSE 5000

CMD ["uwsgi", "wsgi.ini"]

4. docker-compose

vim docker-compose.yml

version: '3.1'

services:
  web:
    build:
      context: ./
      dockerfile: Dockerfile
    restart: always
    container_name: flaskr
    ports:
      - 5000:5000

5. 运行

docker-compose up

你可能感兴趣的:(#,python)