本文介绍了“连接已重置";使用django和docker在localhost:8000中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行 docker-compose up
后,
when i connect to http://127.0.0.1:8000/ it shows thisThere 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"
解决方案
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
这篇关于“连接已重置";使用django和docker在localhost:8000中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!