Dockerfile-For-Python

main

# -*- coding:utf-8 -*-
# @Author: 15b883
from fastapi import FastAPI
import uvicorn
 
app = FastAPI()

Dockerfile

FROM python:3.8.7-alpine3.12

ENV PORT 8080
ENV TIMEZONE=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TIMEZONE /etc/localtime && echo $TIMEZONE > /etc/timezone
EXPOSE 8080


WORKDIR /opt
ADD . /opt
RUN pip install -r requirements.txt

ENTRYPOINT ["sh", "/opt/entrypoint.sh"]

entrypoint

#!/bin/bash

set -e

# ================================================================================
exec python main.py

requirements

fastapi
uvicorn

build

docker build . -t fastapiweb:v1

run

docker run --name web1 -d -p 80:8080 fastapiweb:v1

check

http://localhost/

原文地址:https://www.cnblogs.com/syavingcs/p/14984222.html