如何在Django Docker容器上指定VSCODE调试器的端口?

问题描述 投票:0回答:1
我在Docker容器内有一个Django应用程序。我已经配置了启动。 launch.json

{ "version": "0.2.0", "configurations": [ { "name": "Docker: Python - Django", "type": "docker", "request": "launch", "preLaunchTask": "docker-run: debug", "python": { "pathMappings": [ { "localRoot": "${workspaceFolder}/src", "remoteRoot": "/app/src" } ], "projectType": "django", "port": 8000, } } ] }

tasks.json

{ "version": "2.0.0", "tasks": [ { "type": "docker-build", "label": "docker-build", "platform": "python", "dockerBuild": { "tag": "vscodedjangodocker: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" } } ] }

docker-compose.yaml

version: '3.8' # Specify the version at the top services: backend: build: context: . dockerfile: ./Dockerfile container_name: backend command: python manage.py runserver 0.0.0.0:8000 ports: - 8000:8000 volumes: - .:/app dockerfile

FROM python:3.12-bullseye

WORKDIR /app/src/

COPY ./src/requirements.txt .

RUN pip install --prefer-binary -r requirements.txt

COPY ./src /app/src

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

我面临的问题是,我希望调试器会话在本地计算机上的端口8000上运行,但是每次我运行调试器时,打开的端口为5500X(即55001,55002等)。例如,当我单击VSCODE上的“开始调试”按钮时,构建的容器将在端口55012:8000.上运行。 当我只运行Docker与docker组成

docker-compose ---build
命令,它可以按预期运行,并且服务器在我的机器的端口8000上运行,但没有附加的调试器。
如何指定我要在端口8000上会话的VSCODE调试器?

我认为您必须将"port": 8000添加到这样的键:

configurations

django docker visual-studio-code debugging
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.