Don't see Django in Docker container

前端 未结 3 1314
攒了一身酷
攒了一身酷 2021-01-27 17:22

I want to run Django in a simple Docker container.

First I built my container with Docker-file. There wasn\'t anything special in it (only FROM, RUN and COPY commands)

3条回答
  •  情歌与酒
    2021-01-27 17:36

    The problem is that you're exposing the development server to 127.0.0.1 inside your Docker container, not on the host OS. If you access another console to your container and do a http request to 127.0.0.1:8000 it will work.

    The key is to make sure the Docker container exposes the development server to all IPv4 addresses, you can do this by using 0.0.0.0 instead of 127.0.0.1.

    Try running the following command to start your Django development server instead:

    python manage.py runserver 0.0.0.0:8000
    

    Also, for further inspiration, you can check out this working Dockerfile for hosting a Django application with the built-in development server https://github.com/Niklas9/django-unixdatetimefield/blob/master/Dockerfile.

提交回复
热议问题