我正在尝试在docker容器中调试我的应用程序。这个应用是用paython2.7编写的,但是VS Code试图用python3来调试它。因此,它不能解析包并抛出异常。
有什么想法吗?
我的配置:
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": ["docker-build"],
"dockerRun": {
"containerName": "account",
"image": "account:latest",
"env": {},
"volumes": [
{
"containerPath": "/code",
"localPath": "${workspaceFolder}"
}
],
"ports": [
{
"containerPort": 8086,
"hostPort": 8086
},
{
"containerPort": 8085,
"hostPort": 8085
}
]
},
"python": {
"args": ["--config=/code/config/account.conf.localstage"],
"file": "skoobe-accountd"
}
},
{
"label": "docker-build",
"type": "docker-build",
"dockerBuild": {
"context": "${workspaceFolder}",
"dockerfile": "${workspaceFolder}/Dockerfile.arm.dev",
"tag": "account:latest"
}
}
]
}launch.json
{
"configurations": [
{
"name": "Debug Account",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/code"
}
],
"projectType": "general"
}
}
]
}settings.json
{
"python.linting.pylintEnabled": true,
"python.pythonPath": "/usr/bin/python"
}Dockerfile
FROM python:2.7.18
ENV AWS_ACCESS_KEY_ID="xxx"
ENV AWS_SECRET_ACCESS_KEY="xxx"
ENV AWS_DEFAULT_REGION="xxx"
ENV SQS_QUEUE="xxx"
ENV SQS_CHANGE_QUEUE="xxx"
# RUN mkdir -p /root/.ssh && \
# chmod 0700 /root/.ssh
# RUN apt-get update && \
# apt-get install openssh-server -y
WORKDIR /code/
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
WORKDIR tools/
RUN python setup.py install
WORKDIR /code/
# RUN pip install -r requirements.txt
CMD ["python", "accountd", "--config=/code/config/account.conf.localstage"]发布于 2021-09-30 15:34:24
经过一番调查,我找到了一个解决方案:
我将lunch.json修改为以下内容:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/code"
}
]
}
]
}然后,我在入口Python文件中添加了以下几行:
import ptvsd
ptvsd.enable_attach(address=('0.0.0.0', 5678))从VS code IDE运行docker容器后,我可以在调试模式下运行。
https://stackoverflow.com/questions/69360649
复制相似问题