首页 > 解决方案 > 为什么使用 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"```

标签: djangodocker-compose

解决方案


推荐阅读