使用docker-compose up时,为什么Django运行服务器挂起?

时间:2019-08-21 18:18:41

标签: django docker-compose

当我运行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时,系统退出Gracefully(lol)。然后我运行docker-compose日志,它显示正确的信息:

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文档中的版本。

0 个答案:

没有答案