FROM python:3.10-slim ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai WORKDIR /app # 第一批:基础工具和基础依赖 RUN apt-get update && apt-get install -y \ --no-install-recommends \ git \ curl \ wget \ vim \ nano \ tzdata \ sudo \ && rm -rf /var/lib/apt/lists/* # 第二批:基础编译工具 RUN apt-get update && apt-get install -y \ --no-install-recommends \ make \ patch \ bzip2 \ xz-utils \ dpkg-dev \ && rm -rf /var/lib/apt/lists/* # 第三批:完整gcc工具链 RUN apt-get update && apt-get install -y \ --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* # 第四批:图形库和SSH RUN apt-get update && apt-get install -y \ --no-install-recommends \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ libgomp1 \ openssh-server \ && rm -rf /var/lib/apt/lists/* RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN pip install --no-cache-dir --upgrade pip setuptools wheel # 分层安装依赖:利用Docker缓存实现差分下载 # 第一层:基础依赖 - 大文件、不常变,会被长期缓存 COPY requirements-base.txt . RUN pip install --no-cache-dir -r requirements-base.txt # 第二层:额外依赖 - 小文件、可能频繁变更,只重新下载这一层 COPY requirements-extra.txt . RUN pip install --no-cache-dir -r requirements-extra.txt RUN curl -fsSL https://code-server.dev/install.sh | sh RUN useradd -m -u 1000 vnpy && echo "vnpy ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && mkdir -p /home/vnpy/.ssh && chown -R vnpy:vnpy /home/vnpy /app && chmod 700 /home/vnpy/.ssh RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config && echo "vnpy:sanguo123" | chpasswd USER vnpy RUN mkdir -p /home/vnpy/.config/code-server && echo 'bind-addr: 0.0.0.0:8080' > /home/vnpy/.config/code-server/config.yaml && echo 'auth: password' >> /home/vnpy/.config/code-server/config.yaml && echo 'password: sanguo123' >> /home/vnpy/.config/code-server/config.yaml EXPOSE 8888 8000 8080 2222 COPY --chown=vnpy:vnpy entrypoint.sh /app/ RUN chmod +x /app/entrypoint.sh COPY --chown=vnpy:vnpy scripts /app/scripts RUN chmod +x /app/scripts/*.sh ENTRYPOINT ["/app/entrypoint.sh"]