流程
windows需安装Docker for desktop
已登录docker账号
编写Dockerfile文件
# 使用Python作为基础镜像, slim-buster是一个轻量级的镜像, 适合生产环境使用
FROM python:3.9-slim-buster
# 设置工作目录
WORKDIR /app
# 复制应用代码到容器中
COPY . .
# 安装依赖项
RUN pip install --no-cache-dir --upgrade -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
# 安装js运行环境
RUN apt-get update && apt-get install -y nodejs npm
# 设置启动命令
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5000"]
构建镜像
docker build -t 1688-scraper-app . --network host
构建镜像时, 执行
RUN apt-get update && apt-get install -y nodejs npm
这条命令时, 很慢, 不知道为什么, 可能是apt-get
的源是国外的
可以试试这里: https://www.cnblogs.com/chentiao/p/17352748.html
修改Dockerfile
# 使用Python作为基础镜像, slim-buster是一个轻量级的镜像, 适合生产环境使用
FROM python:3.12.3-slim-bullseye
# 设置工作目录
WORKDIR /app
# 复制应用代码到容器中
COPY . .
# 安装依赖项
RUN pip install --no-cache-dir --upgrade -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
# 设置为中国国内源
RUN sed -i 's@/deb.debian.org/@/mirrors.aliyun.com/@g' /etc/apt/sources.list
RUN apt-get clean
# 安装j