David Foie Gras
David Foie Gras

Reputation: 2070

Why does Django in docker container not work?

Dockerfile:

FROM python:3.6.5-jessie
MAINTAINER example-user

RUN apt-get update \
    && apt-get install -y vim
RUN mkdir require
COPY ./requirements.txt require/requirements.txt
RUN pip install -r require/requirements.txt
EXPOSE 8000

requirements.txt:

Django==2.0.2

As above, I made a image that has name sample-image

Next, I runned a container from sample-image like,

docker run -ti --name sample_django -p 8001:8000 sample-image /bin/bash

And on container bash, I commanded like,

root@4a947abf5ce5:/# mkdir startdir && cd startdir
root@4a947abf5ce5:/startdir# django-admin startproject sample .
root@4a947abf5ce5:/startdir# python manage.py runserver

it returned it:

Performing system checks...

System check identified no issues (0 silenced).

You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

May 01, 2018 - 12:44:45
Django version 2.0.2, using settings 'sample.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Because I set -p 8001:8000 on running container, I found this page in browser( 127.0.0.1:8080), but it did returned it:

enter image description here

QUESTION: How can I set port on container correctly? Or is there anything i missed?

Upvotes: 2

Views: 1289

Answers (1)

Alasdair
Alasdair

Reputation: 308769

Inside the docker container, use python manage.py runserver 0.0.0.0:8000 so that runserver doesn't just bind to 127.0.0.1.

Upvotes: 6

Related Questions