VS Code: Remote Container: Using SSH

Viewed 606

I have a python app that needs access to private repository which is mentioned in the Dockerfile like this:
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 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. I am getting this in the logs when opening the project in a container using the Remote Contaienr extension:

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:
Start: Run: docker build -f d:\Code\somename\Dockerfile -t vsc-somename-8afa92e4f821805c825a5facd311c4f9 d:\Code\somename

devcontainer.json file:

// 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.

1 Answers

I think this reference page can help you find the right syntax to customize docker commands using the devcontainer.json.

Unfortunately, it seems you can't specify arguments to be passed to your docker build command directly. You can only pass in 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.

Related