简体   繁体   English

我的本地 API 127.0.0.1:8000 不适用于 docker

[英]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.

相关问题 当没有文件重定向URL django时,我在127.0.0.1:8000的本地端口始终重定向到127.0.0.1:8000/myapp/lists - my local port at 127.0.0.1:8000 always redirects to 127.0.0.1:8000/myapp/lists when no file redirects url django 一切正常,但我的127.0.0.1:8000无法显示任何内容,为什么? 我用django-sphinx - Everything is ok, but my 127.0.0.1:8000 can't show anything, why ? I used django-sphinx Change URL of browsable API of django rest framework from 127.0.0.1:8000 to 127.0.0.1:8000/api - Change URL of browsable API of django rest framework from 127.0.0.1:8000 to 127.0.0.1:8000/api localhost:8000 工作但 mywebsite:8000 与 etc/hosts 修改不起作用 - localhost:8000 working but mywebsite:8000 with etc/hosts modified doesn't work 如何将我的Django路径设置为http://127.0.0.1:8000/myproject/admin - how to set my django path to http://127.0.0.1:8000/myproject/admin 如何从安卓平板访问我的 127.0.0.1:8000 - how to access my 127.0.0.1:8000 from android tablet 无法访问Django服务器,请访问http://127.0.0.1:8000/ - Can't access the Django server at http://127.0.0.1:8000/ 为什么我的 localhost:8000 加载与 127.0.0.1:8000 django 网站不同 - Why is my localhost:8000 loading differently from 127.0.0.1:8000 django website TemplateDoesNotExist 在 http://127.0.0.1:8000/ - TemplateDoesNotExist at http://127.0.0.1:8000/ 如何将我的Django应用程序索引页网址从http://127.0.0.1:8000/qa/更改为http://127.0.0.1:8000/? - How do I change my Django app index page url from http://127.0.0.1:8000/qa/ to http://127.0.0.1:8000/?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM