Automatically reloading code changes with the development of Django in Docker with Gunicorn

I use the Docker container to develop Django, and the container runs Gunicorn with Nginx. I would like the code changes to be downloaded automatically, but the only way to download them is to rebuild using docker-compose ( docker-compose build). The problem with the build is that it re-launches all my folder settings.

I am using the Gunicorn flag --reload, which apparently should do what I want. Here are my Docker configuration files:

## Dockerfile:
FROM python:3.4.3
RUN mkdir /code
WORKDIR /code
ADD . /code/
RUN pip install -r /code/requirements/docker.txt

## docker-compose.yml:
web:
  restart: always
  build: .
  expose:
    - "8000"
  links:
    - postgres:postgres
  volumes:
    - /usr/src/app/static
  env_file: .env
  command: /usr/local/bin/gunicorn myapp.wsgi:application -w 2 -b :8000 --reload

nginx:
  restart: always
  build: ./config/nginx
  ports:
    - "80:80"
  volumes:
    - /www/static
  volumes_from:
    - web
  links:
    - web:web

postgres:
  restart: always
  image: postgres:latest
  volumes:
    - /var/lib/postgresql
  ports:
    - "5432:5432"

I tried some other Docker ( docker-compose restart, docker-compose up) commands , but the code is not updating.

What am I missing?

+39
3

kikicarbonell Docker Compose Django, volumes: - .:/code - docker-compose.yml, , , .

## docker-compose.yml:
web:
  restart: always
  build: .
  expose:
    - "8000"
  links:
    - postgres:postgres
  volumes:
    - /usr/src/app/static
    - .:/code
  env_file: .env
  command: /usr/local/bin/gunicorn myapp.wsgi:application -w 2 -b :8000 --reload

: Gunicorn Django Docker, Rackspace, , -machine , Rackspace Cloud.

:, , , (, , Digital Ocean Rackspace). , ​​ . , (, flocker), - , . "fix" - rsync/scp . --reload scp/rsync. :. , (, docker-compose build web && docker-compose up -d). , rsync, src .

+33

- Docker , . pip !

ADD . /code/
RUN pip install -r /code/requirements/docker.txt

. Docker ADD, , - , . ...

ADD ./requirements/docker.txt /code/requirements/
RUN pip install -r /code/requirements/docker.txt
ADD ./code/

, !

+23

, . , , - // " ".

, View, exit(). Django, , . , requests.get . , Docker, .

, PID ( ):

web    | [2019-07-15 18:29:52 +0000] [22] [INFO] Worker exiting (pid: 22)
web    | [2019-07-15 18:29:52 +0000] [24] [INFO] Booting worker with pid: 24

, / .

0
source

All Articles