Deploy to docker with nginx, django, daphne

后端 未结 2 838
温柔的废话
温柔的废话 2021-02-04 18:06

I want to deploy my service to docker.

and my service is developed using python+django and django-channels

── myproject ├── myproject │ ├── sett

2条回答
  •  孤街浪徒
    2021-02-04 18:41

    You have misconfigured NGINX. Try proxy_pass http://127.0.0.1:8000;

    As for the static files, it's because you haven't made the files available to the container. I would suggest the following modifications:

    myproject/Dockerfile:

    [...]
    ADD . /opt/myproject
    VOLUME ["/opt/myproject/collected_static"]
    [..]
    # may I also suggest automatic static file collection?
    RUN python manage.py collectstatic --noinput
    

    myproject/docker-compose.yml:

    [...]
    build: ./nginx
    volumes_from:
      - "worker" # or daphne
    

    I would also consider adding image option to daphne and worker services. This will tag the image and allow to reuse it, thus it will be only built once (instead of twice).

    myproject:
      build: .
      image: "myproject:latest"
    [..]
    worker:
      image: "myproject:latest"
    [..]
    daphne:
      image: "myproject:latest"
    

提交回复
热议问题