【问题标题】:Django server does not start, the site does not work when starting dockerfiledjango服务器不启动,启动dockerfile时站点不工作
【发布时间】:2022-01-19 17:43:34
【问题描述】:

我正在 dockerfile 程序集中进行培训,我不明白为什么它不起作用。 Python django 项目 GitHub: [https://github.com/BrianRuizy/covid19-dashboard][1]

目前我有这么一个dockerfile,谁知道怎么创建docker文件,帮我弄清楚,告诉我我的错误是什么。

FROM python:3.8-slim

RUN apt-get update && \
    apt-get install -y --no-install-recommends build-essential

ENV PYTHONUNBUFFERED=1
ADD requirements.txt /
RUN pip install -r /requirements.txt

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "127.0.0.1:8000"]

【问题讨论】:

    标签: python django docker


    【解决方案1】:

    您从未将文件复制到容器中,示例看起来像这样。这也可以防止以超级用户身份运行

    FROM python:3.8-slim
    
    #INSTALL REQUIREMENTS
    RUN apt-get update
    RUN apt-get -y install default-libmysqlclient-dev gcc wget
    
    # create the app user
    RUN useradd -u 1000 -ms /bin/bash app && mkdir /app && chown -R app:app /app
    
    # copy the requirements
    COPY  --chown=app:app ./requirements.txt /app/requirements.txt
    COPY  --chown=app:app ./deploy-requirements.txt /app/deploy-requirements.txt
    
    WORKDIR /app
    # and install them
    RUN pip install -r requirements.txt && pip install -r deploy-requirements.txt
    
    #####
    #
    # everything below runs as the 'app' user for security reasons
    #
    #####
    
    USER app
    #COPY APP
    COPY --chown=app:app . /app
    WORKDIR /app
    
    #RUN
    ENTRYPOINT gunicorn -u app -g app --bind 0.0.0.0:8000 PROJECT.asgi:application -k uvicorn.workers.UvicornWorker
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 2019-05-16
      • 2017-08-06
      • 1970-01-01
      相关资源
      最近更新 更多