From 4f07faaa640cd258a620faf39e41f65111651950 Mon Sep 17 00:00:00 2001 From: Cxx0822 <1556464090@qq.com> Date: Tue, 6 Jan 2026 19:57:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0fastapi=E5=8D=9A?= =?UTF-8?q?=E5=AE=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/theme/router/index.ts | 6 ++-- docs/DevOps/Docker.md | 2 +- docs/Web-Backend/FastAPI/FastAPI-Docker.md | 33 +++++++++++++++++++ .../SpringBoot/SpringBoot-RestClient.md | 4 +++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 docs/Web-Backend/FastAPI/FastAPI-Docker.md create mode 100644 docs/Web-Backend/SpringBoot/SpringBoot-RestClient.md diff --git a/docs/.vitepress/theme/router/index.ts b/docs/.vitepress/theme/router/index.ts index 11e588a..6310e61 100644 --- a/docs/.vitepress/theme/router/index.ts +++ b/docs/.vitepress/theme/router/index.ts @@ -35,14 +35,16 @@ export const routers = [ { text: 'SpringBoot注解', link: '/Web-Backend/SpringBoot/SpringBoot-Annotation' }, { text: 'SpringBoot3原生镜像', link: '/Web-Backend/SpringBoot/SpringBoot3-GraalVM' }, { text: 'SpringBoot技巧', link: '/Web-Backend/SpringBoot/SpringBoot-Skills' }, - { text: 'SpringBoot Common', link: '/Web-Backend/SpringBoot/SpringBoot-Common' } + { text: 'SpringBoot Common', link: '/Web-Backend/SpringBoot/SpringBoot-Common' }, + { text: 'SpringBoot RestClient简介', link: '/Web-Backend/SpringBoot/SpringBoot-RestClient' } ] }, { text: '🐍 FastAPI', items: [ { text: 'FastAPI基础教程', link: '/Web-Backend/FastAPI/FastAPI-Guide' }, - { text: '基于OAuth2的安全验证', link: '/Web-Backend/FastAPI/OAuth2' } + { text: '基于OAuth2的安全验证', link: '/Web-Backend/FastAPI/OAuth2' }, + { text: 'FastAPI Docker部署', link: '/Web-Backend/FastAPI/FastAPI-Docker' } ] }, { diff --git a/docs/DevOps/Docker.md b/docs/DevOps/Docker.md index c011ae5..966748b 100644 --- a/docs/DevOps/Docker.md +++ b/docs/DevOps/Docker.md @@ -288,7 +288,7 @@ docker system prune -f # 六、Dockerfile   Dockerfile 是用来构建 Docker 镜像的文本文件,包含了一系列构建指令,可以自动化地创建包含应用及其运行环境的镜像。   基本结构: -``` +```dockerfile # 基础镜像 FROM 镜像名:标签 diff --git a/docs/Web-Backend/FastAPI/FastAPI-Docker.md b/docs/Web-Backend/FastAPI/FastAPI-Docker.md new file mode 100644 index 0000000..04da5a2 --- /dev/null +++ b/docs/Web-Backend/FastAPI/FastAPI-Docker.md @@ -0,0 +1,33 @@ +--- + title: FastAPI Docker离线部署 + date: 2026-01-06 +--- + +# 一、安装依赖 +  通过pip将requirements.txt中的依赖包下载到本地: +```sh +pip download -r requirements.txt -d ./packages --only-binary=:all: --platform manylinux2014_x86_64 -i https://pypi.tuna.tsinghua.edu.cn/simple +``` + +::: tip +`--only-binary=:all:`表示只下载预编译的二进制包 +`--platform manylinux2014_x86_64`指定目标平台为 Linux +`-i`指定pip镜像源源 +还可以加上`--python-version 310`指定python版本 +::: + +  执行命令后,会在./packages中下载相应的二进制包。 + +# 二、Dockfile +```dockerfile +FROM python:3.10-slim +WORKDIR /app +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo 'Asia/Shanghai' > /etc/timezone +COPY ./packages /app/packages +COPY requirements.txt /app/ +RUN pip install --no-cache-dir --no-index --find-links=/app/packages -r requirements.txt +COPY . /app/ +EXPOSE 8095 +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8095"] +``` \ No newline at end of file diff --git a/docs/Web-Backend/SpringBoot/SpringBoot-RestClient.md b/docs/Web-Backend/SpringBoot/SpringBoot-RestClient.md new file mode 100644 index 0000000..ffdf228 --- /dev/null +++ b/docs/Web-Backend/SpringBoot/SpringBoot-RestClient.md @@ -0,0 +1,4 @@ +--- + title: SpringBoot RestClient简介 + date: 2026-01-06 +---