M
M
mr_forlife2021-06-25 22:30:01
Django
mr_forlife, 2021-06-25 22:30:01

How to access Django application from Docker?

I am taking my first steps in mastering Docker.
For the sake of experiment, I launched a container based on the ubuntu image

docker run -it -d -p 8000:8000 --name django ubuntu


Installed python and django inside the container
Created a Django project

python3 django-admin startproject site

Then launched the Django test server

python3 manage.py runserver

The server started without errors. I tried to access the Django welcome page outside the container at localhost:8000, 127.0.0.1:8000, but in response I get only

Unable to connect to site.
The page at 127.0.0.1:8000 may be temporarily unavailable or moved to a new address.


What have I done wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-06-25
@mr_forlife

at least - this is how you need to run it:
python3 manage.py runserver 0.0.0.0:8000
otherwise, django listens to the localhost inside its container

S
s7500, 2021-06-26
@s7500

Docker has a great tutorial for working with Django
https://docs.docker.com/samples/django/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question