2015-11-06 55 views
2

我試圖將一個Django項目移植到Docker-Compose上進行部署。Django服務器不會在Docker-Compose中啓動

我跟着各種教程在線和我的理解,我的應用程序需要的唯一服務是Django和Postgres。這裏是我的搬運工,compose.yml文件:

db: 
    image: postgres:latest 
    ports: 
    - "5432" 
    environment: 
    POSTGRES_PASSWORD: postgres 
    POSTGRES_USER: postgres 
web: 
    build: . 
    ports: 
    - "8000:8000" 
    volumes: 
    - .:/code 
    links: 
    - db 
    command: python3 manage.py runserver 0.0.0.0:8000 

我在我的virtualenv本地測試蟒蛇命令和服務器啓動,但是,當我運行該文件夾中的「泊塢窗,撰寫了」的副本應用程序位於,我得到這樣的輸出:

Creating hpr_db_1 
Creating hpr_web_1 
Attaching to hpr_db_1, hpr_web_1 
db_1 | The files belonging to this database system will be owned by user "postgres". 
db_1 | This user must also own the server process. 
db_1 | 
db_1 | The database cluster will be initialized with locale "en_US.utf8". 
db_1 | The default database encoding has accordingly been set to "UTF8". 
db_1 | The default text search configuration will be set to "english". 
db_1 | 
db_1 | Data page checksums are disabled. 
db_1 | 
db_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok 
db_1 | creating subdirectories ... ok 
db_1 | selecting default max_connections ... 100 
db_1 | selecting default shared_buffers ... 128MB 
db_1 | selecting dynamic shared memory implementation ... posix 
db_1 | creating configuration files ... ok 
db_1 | creating template1 database in /var/lib/postgresql/data/base/1 ... ok 
db_1 | initializing pg_authid ... ok 
db_1 | initializing dependencies ... ok 
web_1 | /usr/local/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9. 
web_1 | return f(*args, **kwds) 
web_1 | 
db_1 | creating system views ... ok 
db_1 | loading system objects' descriptions ... ok 
db_1 | creating collations ... ok 
db_1 | creating conversions ... ok 
db_1 | creating dictionaries ... ok 
db_1 | setting privileges on built-in objects ... ok 
db_1 | creating information schema ... ok 
db_1 | loading PL/pgSQL server-side language ... ok 
web_1 | /usr/local/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9. 
web_1 | return f(*args, **kwds) 
web_1 | 
db_1 | vacuuming database template1 ... ok 
db_1 | copying template1 to template0 ... ok 
db_1 | copying template1 to postgres ... ok 
db_1 | syncing data to disk ... ok 
db_1 | 
db_1 | Success. You can now start the database server using: 
db_1 | 
db_1 |  postgres -D /var/lib/postgresql/data 
db_1 | or 
db_1 |  pg_ctl -D /var/lib/postgresql/data -l logfile start 
db_1 | 
db_1 | 
db_1 | WARNING: enabling "trust" authentication for local connections 
db_1 | You can change this by editing pg_hba.conf or using the option -A, or 
db_1 | --auth-local and --auth-host, the next time you run initdb. 
db_1 | waiting for server to start....LOG: database system was shut down at 2015-11-06 15:18:39 UTC 
db_1 | LOG: MultiXact member wraparound protections are now enabled 
db_1 | LOG: autovacuum launcher started 
db_1 | LOG: database system is ready to accept connections 
db_1 | done 
db_1 | server started 
db_1 | ALTER ROLE 
db_1 | 
db_1 | 
db_1 | /docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/* 
db_1 | 
db_1 | LOG: received fast shutdown request 
db_1 | LOG: aborting any active transactions 
db_1 | LOG: autovacuum launcher shutting down 
db_1 | waiting for server to shut down....LOG: shutting down 
db_1 | LOG: database system is shut down 
db_1 | done 
db_1 | server stopped 
db_1 | 
db_1 | PostgreSQL init process complete; ready for start up. 
db_1 | 
db_1 | LOG: database system was shut down at 2015-11-06 15:18:41 UTC 
db_1 | LOG: MultiXact member wraparound protections are now enabled 
db_1 | LOG: database system is ready to accept connections 
db_1 | LOG: autovacuum launcher started 

有關服務器啓動或類似的東西沒有消息,我知道它編譯我的代碼由於對棄用的警告信息,但我在這兒住難倒。任何人都能看到我的錯誤?

UPDATE:

經仔細檢查和更改端口Django的服務器,我發現訪問網頁返回「而頁面加載了與服務器連接被重置」錯誤。這表明正在設置該頁面上的內容。但我仍然無法訪問它。我知道Docker-Compose正在像教程中簡單的Django應用程序一樣工作。

+1

您能否爲您的django網絡應用程序插入您的dockerfile –

回答

3

您是否EXPOSE django容器的端口?

+0

這讓我看着正確的區域,所以我會將其標記爲正確的,正確的端口沒有在我的Django項目中定義的yml文件中選擇settings.py的數據庫部分 – GreenGodot

2

使用.yml文件創建構建。

您應該將文件移至部署環境並繼續運行服務器。

因此,當.yml成功運行時,您將獲得成功構建,並且您將能夠將文件移動到部署環境(最後一個構建運行的位置)。

無論如何,我不推薦在跑步者中執行python3 manage.py runserver 0.0.0.0:8000,因爲你的跑步者將會跑步並且不會完成(取得成功或失敗的構建)。

+0

請您詳細說明最後一句話嗎?爲什麼運行'python3 manage.py runserver 0.0.0.0:8000'不好?你會推薦什麼來運行?我有這個問題,當有一個python錯誤,沒有輸出,服務器不啓動。 – mirosval