Search code examples
djangodockerdjango-admin

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?


Solution

  • 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