【问题标题】:IP error: Django app not deploying with dockerIP 错误:Django 应用程序未使用 docker 部署
【发布时间】:2020-08-12 14:35:52
【问题描述】:

我是 Docker 新手,所以我可能遗漏了一些明显的东西,但这里是。我正在尝试使用 docker postgres 测试一个简单的 Django 应用程序。我现在想要的只是验证主页是否在 localhost 上运行。调试输出窗口给了我以下信息:

web_1  | System check identified no issues (0 silenced).
web_1  | April 28, 2020 - 17:06:23
web_1  | Django version 3.0.5, using settings 'app.settings'
web_1  | Starting development server at http://0.0.0.0:8000/
web_1  | Quit the server with CONTROL-C.

但是,当我转到 0.0.0.0:8000 时,我收到一条错误消息,提示无法访问该站点

"The webpage at http://0.0.0.0:8000/ might be temporarily down or it may have moved permanently to a new web address.

ERR_ADDRESS_INVALID

这是我的 docker-compose.yml:

version: '3.7'

services:
  web:
    build: .
    command: python /app/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/app
    ports:
      - 8000:8000
    depends_on:
      - db
  db:
    image: "postgres:latest"
    ports:
      - "5432:5432"
    environment:
      - "POSTGRES_HOST_AUTH_METHOD=trust"

这是我的 dockerfile:

# Pull base image
FROM python:3.8

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /app

# Install dependencies
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

# Copy project
COPY . /app/
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

非常感谢任何有关故障排除的见解或帮助。因为调试窗口中没有错误,所以我不确定从哪里开始。

谢谢!

【问题讨论】:

  • 试试http://localhost:8000/http://127.0.0.1:8000/
  • 两个都试过了,还是不行

标签: django postgresql docker


【解决方案1】:

有同样的问题。使用Iain Shelvington's comment解决它:

试试http://localhost:8000/http://127.0.0.1:8000/

显然 Dockerfile 中的 0.0.0.0 映射到浏览器中的 localhost

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-08
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 2019-07-03
    相关资源
    最近更新 更多