Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The connection was reset" in localhost:8000 using django and docker

After running docker-compose up,

Starting docker_django ... done

Attaching to docker_django

docker_django | Watching for file changes with StatReloader

docker_django | Performing system checks...

docker_django | System check identified no issues (0 silenced).

docker_django | February 12, 2020 - 07:26:35

docker_django | Django version 3.0.3, using settings 'backend.settings'

docker_django | Starting development server at http://127.0.0.1:8000/

docker_django | Quit the server with CONTROL-C.

when i connect to http://127.0.0.1:8000/ it shows this enter image description here There is no problem / error running the docker-compose command but only when visiting the site.

Im using ubuntu 19.10 and the project has django v3.

Dockerfile

FROM python:3

ENV PYTHONUNBUFFERED 1

RUN mkdir /code
WORKDIR /code

COPY . /code/

RUN pip install -r requirements.txt

docker-compose.yml

version: '3'

services:
    web:
        build: .
        container_name: docker_django
        command: python manage.py runserver
        volumes:
            - .:/code
        ports:
            - "8000:8000"
like image 461
Pipo Avatar asked Feb 12 '20 07:02

Pipo


1 Answers

Your application only listens to requests coming from localhost, which in case of a container are requests coming from inside the container.

Try this compose file:

version: '3'

services:
    web:
        build: .
        container_name: docker_django
        command: python manage.py runserver 0.0.0.0:8000
        volumes:
            - .:/code
        ports:
            - "8000:8000"

corrected typo for port number as suggested

like image 67
Mihai Avatar answered Oct 25 '22 15:10

Mihai