Skip to content

Instantly share code, notes, and snippets.

@firstfu
Created August 29, 2024 03:05
Show Gist options
  • Save firstfu/d79e4916c3fd7c1c0979f52d1c340131 to your computer and use it in GitHub Desktop.
Save firstfu/d79e4916c3fd7c1c0979f52d1c340131 to your computer and use it in GitHub Desktop.
# 使用官方 Python 镜像作为基础镜像
FROM python:3.12
# 设置工作目录
WORKDIR /app
# 将 requirements.txt 复制到工作目录
COPY requirements.txt /app/
# 安装依赖项
RUN pip install --no-cache-dir -r requirements.txt
# 安装 netcat 工具,用于检查服务端口
RUN apt-get update && apt-get install -y netcat-openbsd
# 将整个项目目录复制到工作目录
COPY . /app/
# 切换到包含 manage.py 的目录
WORKDIR /app
# 暴露端口 8000
EXPOSE 8000
# 运行 Django 的静态文件收集(如果你的项目需要)
RUN python manage.py collectstatic --noinput
# 等待数据库服务可用并运行迁移和启动应用程序
CMD ["sh", "-c", "until nc -z db 5432; do echo 'Waiting for the database...'; sleep 1; done; python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment