Benjamin RD
Benjamin RD

Reputation: 12034

Expose port 8000 using docker and django

I'm trying to do a copy of my django image that I found here: https://hub.docker.com/r/library/django

Well, at this point the image is working good, but I'm trying to generate a container from this one.

Well using the commands:

$ docker ps -a
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS                      PORTS               NAMES
3c3e94ff32e7        django:latest          "python3"                18 hours ago        Exited (137) 17 hours ago                       django

$ docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
django              latest              eb40dcf64078        9 months ago        436MB

Using:

$ docker commit django fmf
$ docker run -p 8000:8000 -td fmf /bin/bash

Now, I have the container fmf and I generated a new django project using:

# django-admin startproject test
# python manage.py runserver 8000

But, this port is not open (or at least I can't see any response there). I'm not sure if the port is not open and using a bridge, but I get no reponse from this container.

What I'm doing wrong?

Upvotes: 9

Views: 13786

Answers (3)

Ebad ur Rehman
Ebad ur Rehman

Reputation: 1

You can also use this command to expose the port publicly.

python .\manage.py runserver IP:PORT

python .\manage.py runserver 127.0.0.1:PORT 
python .\manage.py runserver localhost:PORT

python .\manage.py runserver Public_IP:PORT
python .\manage.py runserver Domain_Name:PORT

Note: Make sure you add your hostname or site address to ALLOWED_HOSTS = ["127.0.0.1", "localhost", "Domain_Name", "Public_IP"] in settings.py

Upvotes: 0

Benjamin RD
Benjamin RD

Reputation: 12034

Finally, I found a solution in this thread: https://github.com/docker/for-win/issues/197

Basically, to run the server you should execute it with:

python manage.py runserver 0.0.0.0:8000

in your docker and in your local machine you can see it with:

localhost:8000

Upvotes: 25

Thiago Chagas - Batata
Thiago Chagas - Batata

Reputation: 315

Try to put this on your Dockerfile:

EXPOSE 8000

Or maybe, you could try to see what is going on in your docker. Run this command to open a bash of your docker:

docker exec -it django /bin/bash

And then, see if there is any running process on port 8000.

Upvotes: 1

Related Questions