docker環境下で、git+ssh周りでnpmのinstallに失敗している

実現したいこと

前提

docker環境でnext.jsでの開発を試しています。
プライベートなリポジトリに依存しているものを作っているので、docker環境での開発を試みているのですが、npm のパッケージのinstallに失敗していて、1日溶かしてしまったので、ちょっと諦めて質問をさせてください。

該当のソースコード

実行している環境は、Windows、WSL2のUbuntu(20.04.6)イメージ内部からコマンドを実行しています。

質問に必要そうな個所のコードを抜粋します。

まずは、docker-compose.ymlの抜粋

yml

1version: '3'2services:3 next_shop:4 container_name: next_shop 5 build: . 6 volumes:7 - .:/usr/src/next_shop:cached 8 - ~/.ssh:/root/.ssh:cached 9 ports:10 - '80:80'11 environment:12 - NODE_ENV=development 13 - WATCHPACK_POLLING=true # hot-reload14 tty: true15 stdin_open: true

Dockerfile

Dockerfile

1FROM node:18.4.0 2 3ENV LANG C.UTF-8 4ENV NODE_ENV production 5 6RUN mkdir /usr/src/next_shop 7ENV FRONT_ROOT /usr/src/next_shop 8 9WORKDIR $FRONT_ROOT 10 11RUN apt-get update -qq && \ 12 apt-get install -y openssh-client git vim && \ 13 apt-get clean && \ 14 rm -rf /var/lib/apt/lists/* 15 16COPY ./package.json ./package-lock.json ./tsconfig.json $FRONT_ROOT/ 17 18RUN npm install -g create next-app --typescript 19 20COPY . $FRONT_ROOT 21 22EXPOSE 80

package.json以下の必要な内容を抜粋します。

json

1{2 "dependencies": {3 "@company_name/design_system": "git+ssh://git@github.com:company_name/design_system.git"4 }5 }6}

この状態で、以下のコマンドを実行しています

docker-compose up -d docker exec -it next_shop sh # dockerイメージ内部へログイン npm install

発生している問題・エラーメッセージ

発生したエラーメッセージは以下のものでした。

npm i npm ERR! code 128 npm ERR! An unknown git error occurred npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/company_name/design_system.git npm ERR! git@github.com: Permission denied (publickey). npm ERR! fatal: Could not read from remote repository. npm ERR! npm ERR! Please make sure you have the correct access rights npm ERR! and the repository exists. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2023-07-09T07_00_04_683Z-debug-0.log

試したこと

sshの認証に失敗しているのは分かるので、以下を試しました。

普段はバックエンドを書いているので、npmのパッケージ周りは明るくないので、素っ頓狂なことをしていたらすいません。

dockerイメージ内部の.ssh/configに以下を記述

Host github User git Port 22 Hostname github.com IdentityFile ~/.ssh/id_rsa TCPKeepAlive yes IdentitiesOnly yes

その後、ssh認証自体は成功しているかを確認、これは成功している様子でした。

# ssh -T github.com Hi myname! You've successfully authenticated, but GitHub does not provide shell access.

dockerイメージ内部で、git cloneをしてみた結果、これはcloneに成功しました。

sh

1git clone git@github.com:company_name/design_system.git

ただ以下のコマンドでは失敗しました

sh

1npm install git+ssh://git@github.com:company_name/design_system.git

npm ERR! code 128 npm ERR! An unknown git error occurred npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/company_name/design_system.git npm ERR! git@github.com: Permission denied (publickey). npm ERR! fatal: Could not read from remote repository. npm ERR! npm ERR! Please make sure you have the correct access rights npm ERR! and the repository exists. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2023-07-09T07_15_30_802Z-debug-0.log

この状態で、npm installに失敗しているので、sshの鍵に関しては正しいものを登録できていると思いますが、npm installするときに発生する違いがinstall失敗の原因と推測していますが、それが何か候補を出せないで悩んでいます。

お知恵をお貸しいただければ幸いです。

コメントを投稿

0 コメント