如何在VSCode中为多Docker容器配置Kedro调试器?
实现VSCode中指定Docker容器调试Kedro流水线
我目前正按照Kedro官方文档的指引,在VSCode中配置Kedro调试器并添加了如下launch.json文件:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Kedro Run", "type": "python", "request": "launch", "console": "integratedTerminal", "module": "kedro", "args": ["run"] // Any other arguments should be passed as a comma-seperated-list // e.g "args": ["run", "--pipeline", "pipeline_name"] } ] }
但我有两个不同的Docker容器,希望在其中调试Kedro流水线,而当前配置会在普通终端运行调试,无法指定容器,请问是否有办法实现并选择对应容器进行调试?
可行解决方案
方案一:通过远程容器连接调试
- 先安装VSCode的Docker和Dev Containers扩展
- 打开VSCode左侧Docker面板,找到目标容器,右键选择「Attach Visual Studio Code」
- 连接完成后,VSCode会加载容器内的环境,此时直接使用原
launch.json配置即可启动调试(终端和Python环境均为容器内的) - 对两个容器分别执行上述操作,就能在对应容器内调试Kedro流水线
方案二:修改launch.json直接指定容器执行
如果不想切换远程窗口,可以通过docker exec命令直接在指定容器内启动调试,修改后的launch.json示例如下:
{ "version": "0.2.0", "configurations": [ { "name": "Kedro: 容器A调试", "type": "python", "request": "launch", "console": "integratedTerminal", "command": "docker exec -it <容器A名称/ID> python -m kedro run", "args": [], "cwd": "${workspaceFolder}" }, { "name": "Kedro: 容器B调试", "type": "python", "request": "launch", "console": "integratedTerminal", "command": "docker exec -it <容器B名称/ID> python -m kedro run", "args": [], "cwd": "${workspaceFolder}" } ] }
- 替换
<容器A名称/ID>和<容器B名称/ID>为实际的容器标识 - 若需传递Kedro参数(如指定流水线),直接追加到
command中即可,例如:docker exec -it <容器ID> python -m kedro run --pipeline data_processing
注意事项
- 确保容器内已安装Kedro及项目依赖,且项目代码已挂载到容器内(或容器本身包含项目代码)
- 使用远程容器方案时,首次连接可能需要等待VSCode将Python等必要扩展安装到容器内
内容的提问来源于stack exchange,提问作者panky_is
相关产品推荐
相关产品推荐

