1

I'm completely new to Docker and Django and I'm having trouble getting my Docker app to serve inside Django. Currently, I'm running my docker container with this command:

docker run -it --name web -p 8000:8000 --link mysql:db -v ~/directory:/app django

where mysql and django refer to containers defined earlier.

Next, I'm using manage.py to make migrations and migrate, then serving with the following command:

mod_wsgi-express start-server --reload-on-changes --working-directory /app/voting_project /app/voting_project/voting_project/wsgi.py &

When I visit localhost:8000 in my browser, it successfully renders the HTML template, but the CSS and images which I see locally are missing.

The following errors are logged in the console: enter image description here

I've played with the structure of my directories a bit, but I can't seem to get the browser to find anything in localhost:8000/static or localhost:8000/images.

I'm assuming 8000 is mapping to somewhere weird in my local directories, but I realize this could also be caused by a number of other things. Please let me know if I'm making any obvious mistakes.

Thanks so much!

1

This is most likely a problem with the django configuration better fitting to stackoverflow, and not so much a devops problem.

Check the settings.py for the following entries:

INSTALLED_APPS = [
    (...)
    'django.contrib.staticfiles',
]

At the end of this file

STATIC_ROOT='staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = [
     os.path.join(BASE_DIR, 'static'),
]

source Django manual: How to static-files

0
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'  `id`

To get the IP Address of docker container.

Then try curl ip-address:8000.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.