2017-05-01 94 views
0

我做(Django的)(搬運工)Django的web服務器無法啓動

docker-compose up 

我得到

$ docker-compose up 
Starting asynchttpproxy_postgres_1 
Starting asynchttpproxy_web_1 
Attaching to asynchttpproxy_postgres_1, asynchttpproxy_web_1 
postgres_1 | LOG: database system was interrupted; last known up at 2017- 
05-01 18:52:29 UTC 
postgres_1 | LOG: database system was not properly shut down; automatic 
recovery in progress 
postgres_1 | LOG: invalid record length at 0/150F410: wanted 24, got 0 
postgres_1 | LOG: redo is not required 
postgres_1 | LOG: MultiXact member wraparound protections are now enabled 
postgres_1 | LOG: database system is ready to accept connections 
web_1  | Performing system checks... 
web_1  | 
web_1  | System check identified no issues (0 silenced). 

我Dockerfile:

FROM python:3 
ENV PYTHONUNBUFFERED 1 
RUN mkdir /code 
WORKDIR /code 
ADD requirements.txt /code/ 
RUN pip install -r requirements.txt 
ADD . /code/ 

我的搬運工,compose.yml

postgres: 
    image: postgres:latest 
    volumes: 
    - ./code/ 
    env_file: 
    - .env 
    volumes: 
    - /usr/src/app/static 
    expose: 
    - '5432' 
web: 
    build: . 
    command: python3 manage.py runserver 0.0.0.0:8000 
    env_file: 
    - .env 
    volumes: 
    - .:/code 
    links: 
    - postgres 
    expose: 
    - '8000' 

正如你所看到的,django服務器不會啓動。我究竟做錯了什麼?提前致謝。

+0

它表明django無法啓動?我看到'web_1 |系統檢查確定沒有問題(0沉默)。 – johnharris85

+0

johnharris:命令提示符通常會輸出django在默認情況下在0.0.0.0:8000上運行,當webserver啓動時 –

回答

1

首先,嘗試另一個終端

docker ps

檢查,如果你的服務器真的沒有開始運行。

並檢查您的django應用程序啓動時是否準備好postgres數據庫安裝程序,如果不嘗試運行bash腳本以查看連接是否設置在postgress以初始化django容器。

wait-bd.sh

#!/bin/bash 
    while true; do 
    COUNT_PG=`psql postgresql://username:[email protected]:5432/name_db -c '\l \q' | grep "name_db" | wc -l` 
    if ! [ "$COUNT_PG" -eq "0" ]; then 
     break 
    fi 
     echo "Waiting Database Setup" 
     sleep 10 
    done 

和碼頭工人,compose.yml在Django的容器中添加標籤命令:

web: 
    build: . 
    command: /bin/bash wait-bd.sh && python3 manage.py runserver 0.0.0.0:8000 

這個腳本還是等你的數據庫設置,因此將運行django安裝程序容器。