2

I dockerize my django app, this is my Dockerfile:

FROM python:3.6-alpine
EXPOSE 8000
RUN apk add --no-cache make linux-headers libffi-dev jpeg-dev zlib-dev
RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
RUN mkdir /Code
WORKDIR /Code
COPY ./requirements.txt .

RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED 1

COPY . /Code/

ENTRYPOINT python /Code/core/manage.py runserver 0.0.0.0:8000

well, i build my image and I run it:

docker run -p 8000:8000 --link postgres:postgres cath11/test_app

all seems to be done:

enter image description here

but when I open my browser on http://0.0.0.0:8000/ or http://127.0.0.1:8000/ my app does not open

enter image description here

Why my django app seems running on my container, I expose port but I cannot see it in my hosted browser?

So many thanks in advance

Community
  • 1
  • 1
Manuel Santi
  • 1,106
  • 17
  • 46

1 Answers1

3

Use docker-machine ip default to check for the IP, and use it instead of localhost. Technically, the django app is served inside the container, not your local host.

So in your case, you should try http://<ip from the command>:8000/

Alex Ramses
  • 538
  • 3
  • 19
  • seem to work, but how can i link internal ip to my external host for using 127.0.0.1 instead of docker internal? thanks – Manuel Santi Oct 24 '19 at 14:33
  • You might need to redirect your local IP to the docker IP. But that would be hack-ish. Why would you want to do that though? – Alex Ramses Oct 24 '19 at 14:50