JobData/jobs_spider/Dockerfile

38 lines
883 B
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用Python 3.9作为基础镜像
FROM python:3.9-slim
# 设置工作目录
WORKDIR /app
# 设置环境变量
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# 配置环境变量可通过docker run -e 覆盖)
ENV API_BASE_URL=http://124.222.245.240:9999 \
MONGODB_URI=mongodb://localhost:27017 \
MONGODB_DB=job_data \
MAX_PAGES=3 \
PAGE_SIZE=15 \
MIN_WAIT_TIME=10 \
MAX_WAIT_TIME=30 \
ERROR_WAIT_MIN=30 \
ERROR_WAIT_MAX=60
# 复制requirements文件并安装Python依赖
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 复制项目文件
COPY boos_api.py ./
COPY city.json ./
COPY work.json ./
# 创建非root用户
RUN useradd -m -u 1000 crawler && chown -R crawler:crawler /app
USER crawler
# 启动命令
CMD ["python", "boos_api.py"]