Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 495
Benjamin RD Avatar asked Sep 20 '17 14:09

Benjamin RD


2 Answers

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
like image 141
Benjamin RD Avatar answered Oct 03 '22 14:10

Benjamin RD


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.

like image 28
Thiago Chagas - Batata Avatar answered Oct 03 '22 15:10

Thiago Chagas - Batata