Docker - Can't access Django server

后端 未结 1 1614
孤城傲影
孤城傲影 2020-12-30 03:11

I can not connect to django through the port in the container. I\'m using this address: 0.0.0.0.:8000 and see: http://joxi.ru/Dr8MeGLhkBWnLm. I\'m creating an image and a co

相关标签:
1条回答
  • 2020-12-30 03:47

    Your issue:

    CMD ["python", "manage.py", "runserver", "8000"]
    

    In order for it to work, you need to change it to:

    CMD ["python", "manage.py", "runserver", "0.0.0.0", "8000"]
    

    and finally, go to http://127.0.0.1:8000/ in your browser.

    Why? Well, Python thinks you're exposing it on 127.0.0.1 when in reality you want the eth0 address, since that can change, and we don't want to hard code it, we use 0.0.0.0 which means "ALL" interfaces.

    Remember docker 127.0.0.1 IS NOT your host 127.0.0.1, each docker container has its own loopback.

    Extra: If you don't want to write out 0.0.0.0 you can simply write 0 -- does the same thing.

    0 讨论(0)
提交回复
热议问题