How should I pass secrets in cmd.exe

1

My quesiton particularly targets passing an SSH key to a docker build command, where I want to clone a private repository from github.

In order to keep the key private, I just want to pass it as a build argument as in:

docker build ---build-arg ssh_key=$(cat ~/.ssh/github) .

This would be the way for bash, but how'd I do that for cmd.exe?

Florian Bachmann

Posted 2019-04-10T08:12:33.830

Reputation: 11

The same way? Get the content of the file and pass it as an argument. If it's a fixed key why not just use the file? – Seth – 2019-04-10T09:05:34.417

If I'd use a file, I had to use ADD and COPY, which would put the secret in a layer forever. (Though there are late solutions in buildkit, but I want to try without that.)

cmd.exe is not able to do command intepolation with $(). Could you tell me a way to do it? – Florian Bachmann – 2019-04-11T13:08:26.033

You need a way to put command output in a variable. Something I've never learned to do for cmd, but this this question may help you https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file

– Isaac Rabinovitch – 2019-04-22T21:09:55.743

Note that cmd is pretty ancient. If I were doing serious command line stuff on windows, I'd learn powershell. – Isaac Rabinovitch – 2019-04-22T21:11:01.697

No answers