Issue
I am having issues using a private github repo in one of my NestJS apps. When I create the docker image using the docker build
command, the image is successfully created and everything works fine. However I can't use the Dockerfile with docker-compose
.
Here's the part of Dockerfile
where I use the BuildKit
mount feature:
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh npm install
When building the image with Dockerfile
alone I pass the --ssh default
argument, like this and it successfully installs the private repo:
docker build --ssh default -t CONTAINER_NAME .
Following this article, inside the docker-compose.yml
file I have included the $SSH_AUTH_SOCK
like this:
environment:
- NODE_ENV:${NODE_ENV}
- SSH_AUTH_SOCK:${SSH_AUTH_SOCK}
volumes:
- $SSH_AUTH_SOCK:${SSH_AUTH_SOCK}
However I get this error whenever I try to run docker-compose up
#11 44.97 npm ERR! code 128
#11 44.97 npm ERR! An unknown git error occurred
#11 44.97 npm ERR! command git --no-replace-objects ls-remote ssh://[email protected]/organization/repo.git
#11 44.97 npm ERR! [email protected]: Permission denied (publickey).
#11 44.97 npm ERR! fatal: Could not read from remote repository.
#11 44.97 npm ERR!
#11 44.97 npm ERR! Please make sure you have the correct access rights
#11 44.97 npm ERR! and the repository exists.
Any idea what I am doing wrong?
Solution
They have added the ssh flag as option to the build key in compose: https://github.com/compose-spec/compose-spec/pull/234
services:
sample:
build:
context: .
ssh:
- default
Answered By - The Fool Answer Checked By - Robin (WPSolving Admin)