gpt4 book ai didi

python - 在VS Code中调试dockerized Django会导致错误 “Timed out waiting for launcher to connect”

转载 作者:行者123 更新时间:2023-12-02 19:17:03 25 4
gpt4 key购买 nike

我想使用Visual Studio Code中的docker容器调试Django应用程序。
Microsoft发布了指南,该指南是我逐步遵循的:
https://code.visualstudio.com/docs/containers/quickstart-python
但是,当我尝试运行调试器时,出现以下错误消息:

Timed out waiting for launcher to connect

这是我逐步执行的操作:
  • 我使用django-admin startproject helloworld初始化了一个简单的Django应用程序
  • 在VS Code中,我打开了包含manage.py的文件夹
  • 打开命令面板Ctrl + Shift + P,然后选择Docker: Add Docker Files to Workspace...
  • 选择应用程序平台Python: Django
  • 包括Docker Compose文件No
  • 应用程序入口点的相对路径manage.py
  • 您的应用程序侦听哪些端口? 8000

  • VS Codes然后创建了几个文件(见下文)。

    当我尝试启动调试器时(如本指南中所述),我收到以下错误消息:
    Docker: Python - Django
    Error: Timed out waiting for launcher to connect
    终端不会显示任何错误消息,但是会执行以下命令:
    terminal 1
    terminal 2

    .vscode / launch.json:
    {
    "configurations": [
    {
    "name": "Docker: Python - Django",
    "type": "docker",
    "request": "launch",
    "preLaunchTask": "docker-run: debug",
    "python": {
    "pathMappings": [
    {
    "localRoot": "${workspaceFolder}",
    "remoteRoot": "/app"
    }
    ],
    "projectType": "django"
    }
    }
    ]
    }
    .vscode / tasks.json:
    {
    "version": "2.0.0",
    "tasks": [
    {
    "type": "docker-build",
    "label": "docker-build",
    "platform": "python",
    "dockerBuild": {
    "tag": "dockerdebugging:latest",
    "dockerfile": "${workspaceFolder}/Dockerfile",
    "context": "${workspaceFolder}",
    "pull": true
    }
    },
    {
    "type": "docker-run",
    "label": "docker-run: debug",
    "dependsOn": [
    "docker-build"
    ],
    "python": {
    "args": [
    "runserver",
    "0.0.0.0:8000",
    "--nothreading",
    "--noreload"
    ],
    "file": "manage.py"
    }
    }
    ]
    }
    Dockerfile:
    # For more information, please refer to https://aka.ms/vscode-docker-python
    FROM python:3.8-slim-buster

    EXPOSE 8000

    # Keeps Python from generating .pyc files in the container
    ENV PYTHONDONTWRITEBYTECODE 1

    # Turns off buffering for easier container logging
    ENV PYTHONUNBUFFERED 1

    # Install pip requirements
    ADD requirements.txt .
    RUN python -m pip install -r requirements.txt

    WORKDIR /app
    ADD . /app

    # Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
    RUN useradd appuser && chown -R appuser /app
    USER appuser

    # During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
    CMD ["gunicorn", "--bind", "0.0.0.0:8000", "helloworld.wsgi"]
    requirements.txt:
    # To ensure app dependencies are ported from your virtual environment/host machine into your container, run 'pip freeze > requirements.txt' in the terminal to overwrite this file
    django==3.0.3
    gunicorn==20.0.4
  • VS代码版本:1.47.1
  • Python扩展版本:v2020.7.94776
  • 最佳答案

    我的问题是缺少包裹。 Docker通常工作正常,我之前从未遇到任何问题。
    我最初按照官方文档中的描述安装了docker:
    https://docs.docker.com/engine/install/ubuntu/
    但是,当我尝试安装docker.io软件包后,在VS Code中调试工作正常:

    sudo apt install docker.io

    关于python - 在VS Code中调试dockerized Django会导致错误 “Timed out waiting for launcher to connect”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62958329/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com