docker image is runnign but webpage error - Docker

I have a basic django project and I am trying to get it running locally through docker. I have the docker file. I build the docker image. I ran the docker image. It is running, but my webpage shows an error on the screen like it is not connecting to the docker server... Here is what I have:

docker file:

FROM python:3
WORKDIR general
COPY requirements.txt ./
EXPOSE 8000
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Here is how I am buiding and running this project:

omars-mbp:split omarjandali$ docker build -t splitbeta/testing2 .
Sending build context to Docker daemon  223.7kB
Step 1/7 : FROM python:3
 ---> 79e1dc9af1c1
Step 2/7 : WORKDIR general
 ---> 04a6f8a7f92a
Removing intermediate container b2ffb485e485
Step 3/7 : COPY requirements.txt ./
 ---> 649d77ec499e
Step 4/7 : EXPOSE 8000
 ---> Running in 7d8d6fe8de1d
 ---> c328d885a5f1
Removing intermediate container 7d8d6fe8de1d
Step 5/7 : RUN pip install -r requirements.txt
 ---> Running in 1c9aca43dc14
Collecting Django==1.11.5 (from -r requirements.txt (line 1))
  Downloading Django-1.11.5-py2.py3-none-any.whl (6.9MB)
Collecting gunicorn==19.6.0 (from -r requirements.txt (line 2))
  Downloading gunicorn-19.6.0-py2.py3-none-any.whl (114kB)
Collecting pytz (from Django==1.11.5->-r requirements.txt (line 1))
  Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
Installing collected packages: pytz, Django, gunicorn
Successfully installed Django-1.11.5 gunicorn-19.6.0 pytz-2017.3
 ---> 602e88557c8b
Removing intermediate container 1c9aca43dc14
Step 6/7 : COPY . .
 ---> 55cff629cb51
Step 7/7 : CMD python manage.py runserver 0.0.0.0:8000
 ---> Running in efd75f8fb602
 ---> 2cef664a626d
Removing intermediate container efd75f8fb602
Successfully built 2cef664a626d
Successfully tagged splitbeta/testing2:latest
omars-mbp:split omarjandali$ docker run -d spltibeta/testing2

Here is the project running:

omars-mbp:split omarjandali$ docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS               NAMES
fc14f03a18b0        splitbeta/testing2   "python manage.py ..."   3 seconds ago       Up 3 seconds        8000/tcp            loving_volhard

THe webpage is giving the following error when it is supposed to display a template page....

This site can’t be reached

127.0.0.1 refused to connect.

I got it running yesterday but it is not working any more... I dont know why. I didnt change anything

I am logged into my dockerhub account in my terminal

1 answer

  • answered 2017-11-14 23:30 Sören Weber

    It seems your Docker run command doesn't publish port 8000. By default, docker won't publish any container ports on the host system if you don't tell it to explicitly. Try using the -p or --publish option of docker run:

    docker run -d -p 8000:8000 spltibeta/testing2
    

    Alternatively, you can use the -P or --publish-all option to publish all exposed ports of your container on your host system. This will assign a random port on the host.

    docker run -d -P spltibeta/testing2