jhaos
jhaos

Reputation: 37

Dockerized django app don't run in the browser

I'm getting a problem when I run my docker image what I built with the next Dockerfile:

FROM ubuntu:18.04

RUN apt update
RUN apt install -y python3 python3-pip
RUN mkdir /opt/app
COPY Ski4All/ /opt/app/
COPY requirements.txt /opt/app/
RUN pip3 install -r /opt/app/requirements.txt

COPY docker-entrypoint.sh /

EXPOSE 8000
ENTRYPOINT /usr/bin/python3 /opt/app/manage.py runserver 127.0.0.1:8000

With the command docker run -p 8000:8000 -it --rm skiapi

Everything run Ok and I receive the message about the server is running at 127.0.0.1:8000 but when I try to access via browser it says that the connection has been restarted and I can't access to the web. Any tip?

I got this logs from journalctl -xe


abr 26 17:04:51 jhaos-m kernel: docker0: port 1(vethd53f322) entered disabled state
abr 26 17:04:51 jhaos-m kernel: docker0: port 1(vethd53f322) entered disabled state
abr 26 17:04:51 jhaos-m kernel: docker0: port 1(vethd53f322) entered disabled state
abr 26 17:04:51 jhaos-m NetworkManager[1312]: <info>  [1587913491.9849] device (vethd53f322): released from master device docker0
abr 26 17:04:58 jhaos-m kernel: docker0: port 1(vethaa75de2) entered blocking state
abr 26 17:04:58 jhaos-m kernel: docker0: port 1(vethaa75de2) entered disabled state
abr 26 17:04:59 jhaos-m NetworkManager[1312]: <info>  [1587913499.0372] device (docker0): carrier: link connected
abr 26 17:04:59 jhaos-m kernel: docker0: port 1(vethaa75de2) entered blocking state
abr 26 17:04:59 jhaos-m kernel: docker0: port 1(vethaa75de2) entered forwarding state

But I don't know if means something special also with systemctl status looks everythig correct. And I tried to docker logs < container > but I only executes django server and stop it printing nothing.

Thanks

PD: For some who is watching question and are starting with docker remember to rebuild the image when you make any change on the project, dockerfile, etc.. Some errors maybe can be for that.

Upvotes: 0

Views: 281

Answers (2)

Ayush Pallav
Ayush Pallav

Reputation: 1057

Run your server on 0.0.0.0:8000 rather than 127.0.0.1:8000 as the later is not reachable.

0.0.0.0 means all IPv4 addresses on the local machine. If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host listens on 0.0.0.0, it will be reachable at both of those IPs.

Upvotes: 1

AzyCrw4282
AzyCrw4282

Reputation: 7744

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/

Upvotes: 0

Related Questions