【问题标题】:Docker NGINX setup to run Django project is giving invalid port specification error运行 Django 项目的 Docker NGINX 设置给出了无效的端口规范错误
【发布时间】:2017-11-05 02:56:26
【问题描述】:

我正在尝试为我的 django 项目设置 Docker。我相信一切都已设置好在我的机器上运行 docker。目前,docker version 提供以下输出:

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 成功构建 docker 镜像并显示以下消息:

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.

还有config/nginx文件夹中的server.conf文件。

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 并遇到此错误。任何指导都会非常有帮助。

【问题讨论】:

  • ./config/nginx 里有什么?
  • 我在config/nginx 文件夹中有server.conf 文件。
  • 问题可能就在那里。可以给我看看吗?
  • 他们说:升级到 Python 3.4.4+ 或 3.5.1+ 应该可以解决问题。
  • 谢谢@罗伯特。它适用于 python 3.5.1+

标签: django nginx docker docker-compose docker-machine


【解决方案1】:

我把答案留在这里以备日后咨询。

根据我们的调查,您的 docker-compose 版本 (

错误:https://github.com/docker/compose/issues/4729

他们建议升级到 Python 3.4.4+ 或 3.5.1+,应该会修复。

【讨论】:

    【解决方案2】:

    web服务中,添加:

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

    更多信息:docker nginx

    【讨论】:

    • 因为他没有所需的模板(文档中提到)所以它不起作用
    猜你喜欢
    • 2020-07-04
    • 2021-09-11
    • 2020-11-27
    • 1970-01-01
    • 2019-06-01
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多