Docker Community Forums

Share and learn in the Docker community.

SSH private repos with docker and yarn

We are currently pulling private repos using ssh and npm.

# syntax=docker/dockerfile:experimental
FROM node:14.15.4-alpine
EXPOSE 4800

# Below is needed so that postinstall scripts can run inside docker
RUN npm set unsafe-perm true

COPY . /workspace
WORKDIR /workspace
# Install ssh client and git
RUN apk add --no-cache openssh-client git

# Download public key for github.com
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

RUN --mount=type=ssh npm ci

CMD ["npm", "run", "start:docker"]

Everything works fine. However, we want to move to yarn for other reasons. But this

# syntax=docker/dockerfile:experimental
FROM node:14.15.4-alpine
EXPOSE 4800

# Below is needed so that postinstall scripts can run inside docker
RUN yarn config set unsafe-perm true

COPY . /workspace
WORKDIR /workspace
# Install ssh client and git
RUN apk add --no-cache openssh-client git

# Download public key for github.com
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

RUN --mount=type=ssh yarn install

CMD ["yarn", "start:docker"]

throws a 401 on the private repos. I should also add that building locally with yarn has no issues. So the SSH keys are correct.

Is there some deeply nested issue with yarn an ssh?

From the little info we have here, the question is barely related to Docker.
Let me summarize, basically, Yarn works on your host machine but not inside your container.

You’d better try your luck on Yarn or Alpine community.
It is unlikely, given the Docker forum’s activity volume, that someone happens to know the answer is here.

Thanks. I have put this on yarn community and pretty much any community I can find.

Throwing spaghetti at the wall.