django - 为什么使用 docker-compose up 时 Django 运行服务器会挂起?
问题描述
当我运行 docker-compose up 时,Django 开始加载。它通过大约四个步骤。在进行系统检查并识别(0 个问题)后,它会停止显示当前日期和时间。这就是它挂起的地方。没有其他事情发生。
C:\Users\********\Desktop\code\hello>docker-compose up
Creating hello_web_1 ... done
Attaching to hello_web_1
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 | System check identified no issues (0 silenced).
web_1 | August 21, 2019 - 17:33:11
当我执行 docker-compose down 时,系统会优雅地退出(大声笑)。然后我运行 docker-compose logs 并显示正确的信息:
C:\Users\********\Desktop\code\hello>docker-compose logs
Attaching to hello_web_1
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 | System check identified no issues (0 silenced).
web_1 | August 21, 2019 - 17:36:44
web_1 | Django version 2.2.3, using settings 'hello_project.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 | System check identified no issues (0 silenced).
web_1 | August 21, 2019 - 17:55:22
web_1 | Django version 2.2.3, using settings 'hello_project.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
这是我的 Dockerfile 和 docker-compose.yml 的样子:
#Dockerfile:
#Pull base image
From python:3.7-slim
#Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
#Set work directory
WORKDIR /code
#Install dependencies
COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system
#Copy project
COPY . /code/
#*docker-compose.yml:
web:
build: .
command: python /code/manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000"```
- 请注意,我使用的是 docker-compose 版本 1,这就是为什么我的 Web 服务位于文件的根目录的原因。我还省略了每个 Docker 文档的版本。
解决方案
推荐阅读
- python - 加入 PySpark 数据集中每个月的上个月数据
- superset - 超集显示来自查询的动态内容(降价)
- xaml - 如何在选择时更改 xamarin shell 中 flyoutitem 的视觉效果?
- c++ - 有没有办法按照 Arduino IDE 中随机生成的列表的顺序运行函数?
- android - 带有房间和状态处理的 Kotlin Coroutines Flow
- linux - 升级到 Ubunto 19.10 后,我的 Laravel 应用程序无法加载吗?
- javascript - 在 json 数组中的每个 json 对象中添加另一个 json 对象
- django - django 是否可以一次聚合查询集的所有字段
- php - Unity C# - 运行 php 并读取 html 结果
- python - 检测熊猫列中两个刺之间的差异并将它们复制到另一列中