Docker nginx无法启动服务

Docker nginx无法启动服务

我正在运行 docker,并且使用 nginx,无法在本地主机上启动服务器

满的货物跟踪

ERROR: for nginx  Cannot start service nginx: driver failed programming external connectivity on endpoint nz01 (d78b0f770f4e31dab284170c16194b3bed22602d6035af7ddcc9dd83035f50fe): Bind for 0.0.0.0:8000 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.

我的docker-compose.xml

version: '3'

services:
  nginx:
    image: nginx:alpine
    container_name: nz01
    ports:
    - "8000:8000"
    volumes:
    - ./todolist:/todolist
    - ./config/nginx:/etc/nginx/conf.d
    depends_on:
    - web

  rabbitmq:
    image: rabbitmq:latest
    hostname: rabbitmq
    volumes:
    - /var/lib/rabbitmq:/var/lib/rabbitmq
    ports:
    - "5672:5672"
    - "15672:15672"

  db:
    image: mysql:5.7
    restart: always
    ports:
    - "3302:3306"
  web:
    build:
      context: .
    command: >
      sh -c "python manage.py migrate &&
             python manage.py runserver 0.0.0.0:8000"
    volumes:
      - ./todolist:/todolist
    ports:
      - "8000:8000"
    depends_on:
      - db
      - rabbitmq

  celery:
    build: .
    command: celery -A todolist worker -l info
    volumes:
       - ./todolist:/todolist
    depends_on:
    - db
    - rabbitmq
  celery-beat:
    build: .
    command: celery -A todolist beat -l info
    volumes:
       - ./todolist:/todolist
    depends_on:
    - db
    - rabbitmq
    - celery

  memcached:
    image: memcached:latest
    ports:
    - "11211:11211"
    entrypoint:
    - memcached
    - -m 64

Nginx conf 文件是

client_max_body_size 10M;

upstream web {
  ip_hash;
  server web:8000;
}

server {

    location /static/ {
        autoindex on;
        alias /src/static/;
    }

    location /media/ {
        autoindex on;
        alias /src/media/;
    }

    location / {
        proxy_pass http://web/;
    }
    listen 8000;
    server_name localhost;
}

答案1

您正在尝试在两个不同的容器上公开端口 8000。每个公开端口的容器都必须使用主机上唯一的端口号。

相关内容