无法使用 vs 代码连接到容器中的 django 进程 运行

Cant connect to django process running in container with vs-code

我无法连接到使用 vs-code 生成的容器内的 django 进程 运行。一切似乎都在工作,我收到了服务器的启动消息,但是当连接到 localhost:8000 时,我没有收到任何响应...

我在启动容器时收到已发布的端口消息:

Published Ports: 8000/tcp -> 127.0.0.1:8000

并且在启动 launch.json 调试时也是一个干净的开始

System check identified no issues (0 silenced). October 13, 2019 - 17:45:05 Django version 2.2.6, using settings 'fpl-django.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.

为什么我无法访问网站:localhost:8000?

devcontainer.json:

    // For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/docker-existing-dockerfile
{
  "name": "Existing Dockerfile",
  // Sets the run context to one level up instead of the .devcontainer folder.
  "context": "..",
  // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
  "dockerFile": "../docker/dev/python/Dockerfile",
  // The optional 'runArgs' property can be used to specify additional runtime arguments.
  "runArgs": [
    // Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker for details.
    // "-v","/var/run/docker.sock:/var/run/docker.sock",
    // Uncomment the next line if you will be using a ptrace-based debugger like C++, Go, and Rust.
    // "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
    // You may want to add a non-root user to your Dockerfile. On Linux, this will prevent
    // new files getting created as root. See https://aka.ms/vscode-remote/containers/non-root-user
    // for the needed Dockerfile updates and then uncomment the next line.
    // "-u", "vscode"
    "--network",
    "fpl-django_default"
  ],
  // Use 'settings' to set *default* container specific settings.json values on container create.
  // You can edit these settings after create using File > Preferences > Settings > Remote.
  "settings": {
    "terminal.integrated.shell.linux": "/bin/bash",
    "python.pythonPath": "/usr/local/bin/python",
    "python.linting.pylintEnabled": true,
    "python.linting.pylintPath": "/usr/local/bin/pylint",
    "python.linting.enabled": true
  },
  // Uncomment the next line if you want to publish any ports.
  "appPort": [
    8000
  ],
  // Uncomment the next line to run commands after the container is created - for example installing git.
  // "postCreateCommand": "apt-get update && apt-get install -y git",
  // Add the IDs of extensions you want installed when the container is created in the array below.
  "extensions": [
    "ms-python.python",
  ]
}

launch.json:

    {
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Django",
      "type": "python",
      "request": "launch",
      "program": "${workspaceFolder}/manage.py",
      "console": "integratedTerminal",
      "args": [
        "runserver",
        "--noreload",
        "--nothreading"
      ],
      "django": true
    }
  ]
}

尝试使用此参数 运行 manage.py runserver0.0.0.0:8000,这将告诉您的应用程序监听来自任何主机的请求。像这样:

{
      "name": "Python: Django",
      "type": "python",
      "request": "launch",
      "program": "${workspaceFolder}/manage.py",
      "console": "integratedTerminal",
      "args": [
        "runserver",
        "0.0.0.0:8000",
        "--noreload",
        "--nothreading"
      ],
      "django": true
}