-1

I am running docker and with that I am using nginx and cant start server on localhost

full tracktrace

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.

my docker-compose.xml is

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

and Nginx conf file is

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
  • Consider that in the error message, the response of "Bind for 0.0.0.0:8000 failed: port is already allocated" is telling you that there's some other service already listening on that port. Oct 16, 2020 at 22:54

1 Answer 1

0

You are trying to expose port 8000 on two different containers. Each container where you expose ports must use a unique port number on the host.

2
  • I was using web on 8000. but now I want to use that using nginx . so what should I do ?
    – TNN
    Oct 7, 2020 at 19:52
  • Change one of the port numbers, or don't expose ports when it is not necessary. Oct 7, 2020 at 21:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .