I'm trying to install a code library from a private repository on GitHub during a Docker build, but I'm running into issues. My current package.json looks like this: "dependencies": { "my-utilities": "github:MYORG/my-utilities" }. Here's my Dockerfile:
```
FROM public.ecr.aws/amazonlinux/amazonlinux:2023
RUN dnf update -y && dnf install -y awscli jq nodejs22
WORKDIR /
COPY package.json /
COPY index.js /
ARG GITHUB_PAT
RUN npm config set "@MYORG:registry" https://npm.pkg.github.com
RUN npm config set "//npm.pkg.github.com:_authToken" "${GITHUB_PAT}"
RUN npm i
CMD ["node", "index.js"]
```
When I try building with `docker build --build-arg GITHUB_PAT="github_pat_XXXXXX" -t utilities-test .`, I get an error:
```
npm error code ENOENT
npm error syscall spawn git
npm error path git
npm error errno -2
npm error enoent An unknown git error occurred
```
Running `npm i` from the command line works fine, so I suspect something's not right with the .npmrc configuration during the build. Any ideas on how to fix this?
4 Answers
Why not publish your package to GitHub Packages directly? You can change your dependency in `package.json` to use a standard package format like "@MYORG/my-utilities": "^1.0.0" instead. This way, your existing npm config would work seamlessly.
It's generally unsafe to use ARG for secrets since they can end up in your image history. Look into using `--secret` mounts for better security during your builds.
Your `npmrc` configuration and the way you're trying to pull the GitHub repo are conflicting. The way you currently have it set up indicates to `npm` to clone it directly, which ignores any auth tokens you set in `.npmrc`. If you want to keep pulling from Git, consider setting up a `.netrc` file with your credentials instead.
It looks like you're missing Git in your base image, which is why you're getting that error. You should install Git as part of your Docker build. You could modify your Dockerfile to include:
```
RUN dnf install -y git
```
This should help with the cloning issue. Just remember, you may run into more problems down the line, but fixing this should be a good start!

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically