realpython / dockerizing-django

https://realpython.com/blog/python/django-development-with-docker-compose-and-machine/
1.34k stars 484 forks source link

collectstatic question #32

Closed jeffusan closed 8 years ago

jeffusan commented 8 years ago

I just pulled this repo to try it out. It works great but I'm not able to collect static admin files correctly.

$ docker-compose run nginx ls /usr/src/app/static
main.css

$ docker-compose run web ls /usr/src/app/static     
main.css

$ docker-compose run web /usr/local/bin/python manage.py collectstatic --noinput
Copying '/usr/local/lib/python3.5/site-packages/django/contrib/admin/static/admin/css/login.css'
...
62 static files copied to '/usr/src/app/static'.

$ docker-compose run web ls /usr/src/app/static
main.css

I was expecting to see the static files from the collectstatic command. Should I collect static files another way?

mjhea0 commented 8 years ago

https://github.com/realpython/dockerizing-django/issues/13

jeffusan commented 8 years ago

Thanks!

I added the shell script to the web image. I modified the path to manage.py in the shell script:

#!/bin/sh
python /user/src/app/manage.py collectstatic --noinput
/usr/local/bin/gunicorn docker_django.wsgi:application -w 2 -b :8000

And then in the production.yml modifIed the path to the shell script:

web:
  restart: always
  build: ./web
  expose:
    - "8000"
  links:
    - postgres:postgres
    - redis:redis
  env_file: .env
  command: /usr/src/app/shell-script.sh

and this works great.

I find it odd that ls does not display the new directory in the web container now, but does in nginx:

$ docker-compose run nginx ls /usr/src/app/static
admin main.css

$ docker-compose run web ls /usr/src/app/static     
main.css