Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to runserver with docker-compose up

I am using Docker while development. I noticed that I can't launch dev server with docker-compose up command, but can with docker-compose run

Here is my Dockerfile:

FROM python:3.6

WORKDIR /opt/lib
RUN pip install --upgrade pip
COPY requirements.txt ./
RUN pip install -r requirements.txt

WORKDIR /opt/web

Here is docker-compose.yaml

version: '2'
services:
  web:
    build: ./web/
    working_dir: /opt/web
    ports:
      - "3000:3000"
    volumes:
      - ./web:/opt/web
    user: 1000:1000
    depends_on:
      - database
    env_file: env
    command: python manage.py runserver 0.0.0.0:3000

  database:
    image: mdillon/postgis:9.6
    ports:
      - "5432:5432"
    volumes:
      - ./database/data:/var/lib/postgresql/data

Now, if I run docker-compose up, only database starts up: enter image description here

But with docker-compose run server starts fine: enter image description here

If I change docker-compose.yml > services > web > command to /usr/local/bin/gunicorn project.wsgi:application -w 4 -b :3000 it also works fine, but I need autorestart when files change enter image description here

I use Docker for MacOS Version 18.03.1-ce-mac65 (24312), Django==1.10

I tried to reset it to factory settings and this did not help.

Can you help me with this?

EDIT 1:

Other manage.py commands, like migrate, work fine

like image 847
atomAltera Avatar asked May 08 '18 09:05

atomAltera


2 Answers

the ./manage.py runserver requires to Allocate a pseudo-TTY. You can pass it to docker-compose.yml this way

services:
  web:
    tty: true
    command: ./manage.py runserver 0:3000
like image 88
Mazel Tov Avatar answered Nov 09 '22 10:11

Mazel Tov


As you mentioned later, you should specify the command in compose file, but with reload option.

Like this:

command: /usr/local/bin/gunicorn project.wsgi:application -w 4 -b :3000 --reload

official docs ref

like image 2
trust512 Avatar answered Nov 09 '22 12:11

trust512