Docker nginx Cannot start service

Fawad Rana asked:

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;
}

My answer:


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.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.