John Smith
John Smith

Reputation: 121

django runserver hangs in docker-compose up but runs correctly in docker-compose run

Edit

Adding --ipv6 to the command, while not properly configured for, seem to surpass the point where the process hangs.

enter image description here

Problem

docker-compose up

docker-compose run -p 8000:8000 web python manage.py runserver 0.0.0.0:8000

Questions

How come I can run the server directly from docker-compose in my shell but not from the .yml file?

To me, the content of the .yml file and the docker-compose run line from the shell are strikingly similar.

The only difference I can think of would perhaps be permissions at some level required to properly start a django server, but I don't know how to address that. Docker runs on a windows 8.1 machine. The shared folder for my virtual machine is the default c:\Users.

Files

My folder contain a fresh django project as well as these docker files. I've tampered with different versions of python and django but the result is the same. I've cleaned up my images and containers between attempts using

docker rm $(docker ps -a -q)
docker rmi $(docker images -q)

docker-compose.yml

version: '3'
services:
    web:
        build: .
        command: python manage.py runserver 0.0.0.0:8000
        volumes:
            - .:/code
        ports:
            - "8000:8000"

Dockerfile

FROM python:3.6-alpine
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/

requirements.txt

Django>=1.8,<2.0

System

My operative system is windows 8.1

Upvotes: 2

Views: 1781

Answers (2)

n00dl3
n00dl3

Reputation: 21584

I was hit by this issue myself and it seems that you need to allocate a tty and a stdin to your container in order to make runserver work:

  python:
    image: my-image:latest
    stdin_open: true # docker run -i
    tty: true # docker run -t
    build:
      context: ..
      dockerfile: docker/Dockerfile

Upvotes: 4

Caleb Loveland
Caleb Loveland

Reputation: 11

I had the same issue and could not get it to do anything else. However when i went to the ip of the docker machine docker-machine ip it returned 192.168.99.100, then by going to 192.168.99.100:8000 my docker container started receiving the requests

Upvotes: 1

Related Questions