简体   繁体   English

VS 代码:远程容器:使用 SSH

[英]VS Code: Remote Container: Using SSH

I have a python app that needs access to private repository which is mentioned in the Dockerfile like this:我有一个 python 应用程序需要访问 Dockerfile 中提到的私有存储库,如下所示:
RUN --mount=type=ssh pip install -r requirements.txt
I have followed instruction from this official docker docs and things are working fine when I do我已按照官方 docker 文档的说明进行操作,当我这样做时一切正常
docker build --ssh default=C:\Users\Ravi.Kumar\.ssh\id_rsa -t somename:latest. from the command line in host machine.从主机中的命令行。
Now I am trying to get this to work using the VSCode Remote Container extension.现在我正在尝试使用 VSCode Remote Container扩展来让它工作。 I am getting this in the logs when opening the project in a container using the Remote Contaienr extension:使用Remote Contaienr扩展在容器中打开项目时,我在日志中得到了这个:

Container server: Remote to local stream terminated with error: {
  message: 'connect ENOENT \\\\.\\pipe\\openssh-ssh-agent',
  name: 'Error',
  stack: 'Error: connect ENOENT \\\\.\\pipe\\openssh-ssh-agent\n' +
    '\tat PipeConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)'
}

Also then the remote container starts, I can see this is the docker build command being used:然后远程容器启动,我可以看到这是正在使用的 docker 构建命令:
Start: Run: docker build -fd:\Code\somename\Dockerfile -t vsc-somename-8afa92e4f821805c825a5facd311c4f9 d:\Code\somename

devcontainer.json file: devcontainer.json 文件:

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.217.4/containers/docker-existing-dockerfile
{
    "name": "Existing Dockerfile",
    "context": "..",
    "dockerFile": "../Dockerfile",
    "settings": {},
    "build": {},
    "extensions": []
}

Question: How do I tell Remote Container extension to use the --ssh arg in the docker build command.问题:如何告诉Remote Container扩展在docker build命令中使用--ssh arg。

I think this reference page can help you find the right syntax to customize docker commands using the devcontainer.json .我认为此参考页面可以帮助您找到使用devcontainer.json自定义 docker 命令的正确语法。

Unfortunately, it seems you can't specify arguments to be passed to your docker build command directly.不幸的是,您似乎无法指定 arguments 直接传递给您的docker build命令。 You can only pass in build-args :您只能传入build-args

"build": { "args": { "MYARG": "MYVALUE"} }

A potential workaround to your problem can be to build the image using the command line you mentionned, and then running Attach to running container... vscode action to work inside it from your vscode instance.您的问题的一个潜在解决方法是使用您提到的命令行构建图像,然后运行Attach to running container... vscode 操作以从您的 vscode 实例在其中工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM