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:
But with docker-compose run
server starts fine:
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
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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With