2017-06-04 163 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

相关问题