返回 MoneyPrinterTurbo
Dockerfile
根目录 / Dockerfile
1 # Use an official Python runtime as a parent image
2 FROM python:3.11-slim-bullseye
3
4 # Set the working directory in the container
5 WORKDIR /MoneyPrinterTurbo
6
7 # 设置/MoneyPrinterTurbo目录权限为777
8 RUN chmod 777 /MoneyPrinterTurbo
9
10 ENV PYTHONPATH="/MoneyPrinterTurbo"
11
12 # 本地用户默认继续优先使用国内镜像;GitHub Actions 发布 GHCR 镜像时使用 default,
13 # 避免海外 runner 访问国内镜像过慢导致镜像发布长时间卡住。
14 ARG DOCKER_BUILD_MIRROR=china
15 ARG PIP_USE_OFFICIAL=0
16
17 # Install system dependencies with retry logic
18 RUN if [ "$DOCKER_BUILD_MIRROR" = "china" ]; then \
19 echo "deb http://mirrors.aliyun.com/debian bullseye main" > /etc/apt/sources.list && \
20 echo "deb http://mirrors.aliyun.com/debian-security bullseye-security main" >> /etc/apt/sources.list; \
21 else \
22 echo "Using default Debian mirrors"; \
23 fi && \
24 ( \
25 for i in 1 2 3; do \
26 echo "Attempt $i: installing system dependencies"; \
27 apt-get update && apt-get install -y --no-install-recommends \
28 git \
29 imagemagick \
30 ffmpeg && break || \
31 echo "Attempt $i failed, retrying..."; \
32 if [ "$DOCKER_BUILD_MIRROR" = "china" ] && [ $i -eq 3 ]; then \
33 echo "Aliyun mirror failed, switching to Tsinghua mirror"; \
34 sed -i 's/mirrors.aliyun.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
35 sed -i 's/mirrors.aliyun.com\/debian-security/mirrors.tuna.tsinghua.edu.cn\/debian-security/g' /etc/apt/sources.list && \
36 ( \
37 apt-get update && apt-get install -y --no-install-recommends \
38 git \
39 imagemagick \
40 ffmpeg || \
41 ( \
42 echo "Tsinghua mirror failed, switching to default Debian mirror"; \
43 sed -i 's/mirrors.tuna.tsinghua.edu.cn/deb.debian.org/g' /etc/apt/sources.list && \
44 sed -i 's/mirrors.tuna.tsinghua.edu.cn\/debian-security/security.debian.org/g' /etc/apt/sources.list; \
45 apt-get update && apt-get install -y --no-install-recommends \
46 git \
47 imagemagick \
48 ffmpeg; \
49 ); \
50 ); \
51 fi; \
52 sleep 5; \
53 done \
54 ) && rm -rf /var/lib/apt/lists/*
55
56 # Fix security policy for ImageMagick
57 RUN sed -i '/<policy domain="path" rights="none" pattern="@\*"/d' /etc/ImageMagick-6/policy.xml
58
59 # Copy only the requirements.txt first to leverage Docker cache
60 COPY requirements.txt ./
61
62 # 本地默认优先国内 PyPI 镜像;GHCR 发布使用官方 PyPI,避免海外 runner 因跨境镜像访问变慢。
63 RUN if [ "$PIP_USE_OFFICIAL" = "1" ]; then \
64 pip install --no-cache-dir --retries 3 --timeout 60 -r requirements.txt; \
65 else \
66 pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --retries 3 --timeout 60 -r requirements.txt || \
67 pip install --no-cache-dir -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/ --trusted-host mirrors.tuna.tsinghua.edu.cn --retries 3 --timeout 60 -r requirements.txt || \
68 pip install --no-cache-dir --retries 3 --timeout 60 -r requirements.txt; \
69 fi
70
71 # Now copy the rest of the codebase into the image
72 COPY . .
73
74 # Expose the port the app runs on
75 EXPOSE 8501
76
77 # Command to run the application
78 CMD ["streamlit", "run", "./webui/Main.py","--browser.serverAddress=127.0.0.1","--server.enableCORS=True","--browser.gatherUsageStats=False","--server.showEmailPrompt=False"]
79
80 # 1. Build the Docker image using the following command
81 # docker build -t moneyprinterturbo .
82
83 # 2. Run the Docker container using the following command
84 ## For Linux or MacOS:
85 # docker run -v $(pwd)/config.toml:/MoneyPrinterTurbo/config.toml -v $(pwd)/storage:/MoneyPrinterTurbo/storage -p 127.0.0.1:8501:8501 moneyprinterturbo
86 ## For Windows:
87 # docker run -v ${PWD}/config.toml:/MoneyPrinterTurbo/config.toml -v ${PWD}/storage:/MoneyPrinterTurbo/storage -p 127.0.0.1:8501:8501 moneyprinterturbo
88
88 lines Plain Text