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

徘徊边缘 提交于 2021-02-05 06:39:27

问题


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 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"

回答1:


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



来源:https://stackoverflow.com/questions/60183313/the-connection-was-reset-in-localhost8000-using-django-and-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!