[Fixed]-Gunicorn does not find main module with docker

1👍

It’s hard to be 100% sure without seeing your Dockerfile and the full setup but I think the issue is this section of the docker-compose.yml:

volumes:
    - ./web:/usr/src/app

In the repo for the tutorial you linked to the equivalent section is:

volumes:
    - /usr/src/app
    - /usr/src/app/static

This is because by using the python:3.5-onbuild image your code has aleady been baked in to the image and so does not need to be added as a volume.

I assume your reasoning for wanting to add the source code as a host volume mount is so that changes which you make are immediately reflected in the running image for development purposes. If this is the case then I think you should be able to achieve that by changing the problematic section to something like:

volumes:
    - .:/usr/src/app

Which would give you this for the whole web section:

web:
  restart: always
  build: ./web
  expose:
    - "8000"
  links:
    - postgres:postgres
  volumes:
    - .:/usr/src/app
  env_file: .env
  command: /usr/local/bin/gunicorn django_project.wsgi:application -w 2 -b :8000

The only issue is that processes in the container run as root so you may have some issues with file permissions of any files which get created inside the container. If that becomes an issue then there are documented ways of solving it (which would depend on what you need to achieve) or you could always post another question here.

👤joelnb

Leave a comment