2017-06-04 170 views
1

我正在嘗試爲我的django項目設置Docker。我相信一切都設置爲在我的機器上運行docker。目前,docker version給出了下面的輸出:Docker運行Django項目的NGINX設置給出無效的端口規範錯誤

Client version: 1.6.2 
Client API version: 1.18 
Go version (client): go1.2.1 
Git commit (client): 7c8fca2 
OS/Arch (client): linux/amd64 
Server version: 17.05.0-ce 
Server API version: 1.29 
Go version (server): go1.7.5 
Git commit (server): 89658be 
OS/Arch (server): linux/amd64 

我安裝我的docker-compose.yml文件,如下所示:

version: '3' 
services: 
    nginx: 
    restart: always 
    image: nginx:latest 
    container_name: NGINX 
    ports: 
     - "8000:8000" 
    volumes: 
     - ./src:/src 
     - ./config/nginx:/etc/nginx/conf.d 
     - /static:/static 
    depends_on: 
     - web 
    web: 
    restart: always 
    build: . 
    container_name: DJANGO 
    command: bash -c "python manage.py makemigrations && python manage.py migrate && gunicorn loop.wsgi -b 0.0.0.0:8000 --reload" 
    depends_on: 
     - db 
    volumes: 
     - ./src:/src 
     - /static:/static 
    expose: 
     - "8000" 

    db: 
    restart: always 
    image: postgres:latest 
    container_name: PSQL 

docker-compose build成功生成以下消息碼頭工人的圖像,並顯示:

Successfully built 6b13b02488dc 
Successfully tagged loopserver_web:latest 
nginx uses an image, skipping 

但是,當我嘗試運行docker-compose up以下錯誤發生時:

Creating NGINX ... 
Creating NGINX ... error 

ERROR: for NGINX Cannot create container for service nginx: invalid port specification: "None" 

ERROR: for nginx Cannot create container for service nginx: invalid port specification: "None" 
ERROR: Encountered errors while bringing up the project. 

server.conf文件夾在config/nginx文件夾中。

upstream web { 
    ip_hash; 
    server web:8000; 
} 

# portal 
server { 
    location /static/ {  
     autoindex on;  
     alias /static/; 
    } 
    location/{ 
     proxy_pass http://web/; 
    } 
    listen 8000; 
    server_name localhost; 
} 

我第一次使用docker並卡住了這個錯誤。任何指導都會非常有幫助。

+0

你在'。/ config/nginx'中有什麼? – Robert

+0

我在'config/nginx'文件夾裏有'server.conf'文件。 –

+0

問題可能在那裏。你可以請出示嗎? – Robert

回答

1

我離開這裏的答案在未來進行協商。

正如我們的調查,似乎有在你的搬運工,撰寫版本(< 1.12.0)與python3一些問題。

錯誤:https://github.com/docker/compose/issues/4729

他們建議升級到Python的3.4.4+或3.5.1+,並且它應該是固定的。

0

web服務,只需添加:

environment: 
    - NGINX_HOST=foobar.com 
    - NGINX_PORT=80 

瞭解更多信息:docker nginx

+0

它不會工作,因爲他沒有所需的模板(在文檔中提到) – Robert

相關問題