How to set SSH_AUTH_SOCK env variable in docker container windows
Asked Answered
B

1

7

I copying over my ssh key in a dockerfile for dev purposes on a windows machine, but I cannot get the SSH_AUTH_SOCK variable set,

here is my Dockerfile

FROM node:alpine


WORKDIR /usr/src/app
COPY package.json .

ADD id_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa \
  && touch /root/.ssh/known_hosts \
  && ssh-keyscan -H github.com >> /root/.ssh/known_hosts \
  && eval `ssh-agent -s` && ssh-add /root/.ssh/id_rsa

RUN yarn
CMD [ "npm", "start" ]

I tried to eval the result of ssh-agent as well in my compose file

command: >
  sh -c 'eval `ssh-agent -s`
  && ssh-add /root/.ssh/id_rsa
  && echo $SSH_AUTH_SOCK'

And when I executed my simple nodejs file, the SSH_AUTH_SOCK is not set.

printenv doesn't show it as well, is there a way to do this.

I can see there are lots of ssh-agent forwarder solution for linux and osx, but it does not work on windows.

Barman answered 10/5, 2019 at 13:37 Comment(3)
If you are using Docker 18.09 there is a better way to handle passing SSH credentials. See medium.com/@tonistiigi/… and docs.docker.com/develop/develop-images/build_enhancementsPeddler
DOCKER_BUILDKIT=1 docker build --ssh default . returns could not parse ssh: [default]: failed to parse C:/Users/user/AppData/Local/Temp/ssh-IbLoxaMx5H4R/agent.19660: ssh: no key foundBarman
@JoeyHipolito Did you solve this issue?Miltonmilty
S
1

Please note that it works when passing the full path to the actual ssh key, e.g.:

$ docker build --ssh default=c:/users/MY_WINDOWS_USER_NAME/.ssh/id_ed25519 .

or

$ docker build --ssh default=c:/users/MY_WINDOWS_USER_NAME/.ssh/id_rsa .
Shortchange answered 16/2, 2023 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.