[英]My local API 127.0.0.1:8000 doesn't work with docker
I have simple django project with one html page and I try to deploy it with docker. My Dockerfile you can see below:我有一个简单的 django 项目和一个 html 页面,我尝试用 docker 部署它。我的 Dockerfile 你可以在下面看到:
FROM python:3.10.9
ENV PYTHONUNBUFFERED 1
RUN mkdir /app
WORKDIR /app
COPY requirements.txt /app/
RUN pip install -r requirements.txt
COPY . /app/
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
I run my image with next command: docker run -p 8000:8000 --rm 751aa7a2d66f
我用下一个命令运行我的图像:
docker run -p 8000:8000 --rm 751aa7a2d66f
But when I open my browser the localhost with API 127.0.0.1:8000 doesn't work.但是当我打开浏览器时,带有 API 127.0.0.1:8000 的本地主机不起作用。 In the same time I run command
docker ps
and it shows the following: docker ps result同时我运行命令
docker ps
并显示以下内容: docker ps 结果
What's the problem?有什么问题? Thanks in advance for your help.
在此先感谢您的帮助。 For your information I work on windows 7.
供您参考,我在 windows 7 工作。
I tried to run docker run -p 127.0.0.1:8000:8000 --rm 751aa7a2d66f
but it didn't help.我尝试运行
docker run -p 127.0.0.1:8000:8000 --rm 751aa7a2d66f
但它没有帮助。 I also tried to change port of my local machine to 8001 with the same result.我还尝试将本地计算机的端口更改为 8001,结果相同。
You can run django with docker-compose.yml below:您可以使用下面的 docker-compose.yml 运行 django:
version: '3'
services:
my_django_service:
build:
context: .
dockerfile: Dockerfile
command: 'python manage.py runserver 0.0.0.0:8000'
ports:
- 8000:8000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.