开始可以看看我之前的文章关于远程Docker的。
安装vscode 的插件
- 首先确保你的Vscode上安装了remote-ssh,Docker 和 remote-container插件
- 然后在你的远程服务器上也安装上remote-container,Docker插件
- 现在假设你已经安装好了插件
使用vscode进入容器调试
- 点击容器的图标
- 选择IMAGES
有两种方式run
和run interactive
3. 使用VScode进入Vscode内部
使用Run interactive
之后在容器部分可以看到容器建立了
这个时候对着建立的容器右键选择Attach Visual Studio Code
这样就是进入容器内调试Vscode了
- 容器内部需要vscode插件的安装
安装pylance,python的基本插件,这样才可以确保调试程序
- Attach Visual Studio Code进入容器
点击Attach Visual Studio Code进入容器可以看到,需要先向容器安装一些Vscode的插件,确保能连接容器。
下面可以看到连接成功了到容器内部了,左下角可以看到是容器
打开文件夹选择容器目录
创建了测试的python文件,如果发现没有办法调试的话
在插件部分,安装容器内的python插件,点击下图中的下载按钮就可以了
从下面可以看到是容器内的python环境
debug模式成功
!!!一般不能调试运行的情况是使用服务器的python环境是调试失败的。
想使用GPU的方式在VScode 运行Docker
参考链接
Please change your code to your devcontainer.json
修改devcontainer.json
{
"name": "Anaconda (Python 3)",
"build": {
"context": "..",
"dockerfile": "Dockerfile",
"args": {
"NODE_VERSION": "none"
}
},
"settings": {
"python.defaultInterpreterPath": "/opt/conda/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/opt/conda/bin/autopep8",
"python.formatting.yapfPath": "/opt/conda/bin/yapf",
"python.linting.flake8Path": "/opt/conda/bin/flake8",
"python.linting.pycodestylePath": "/opt/conda/bin/pycodestyle",
"python.linting.pydocstylePath": "/opt/conda/bin/pydocstyle",
"python.linting.pylintPath": "/opt/conda/bin/pylint"
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],
"runArgs": ["--gpus","all"
],
"remoteUser": "vscode",
}