Gemini CLIのnpm installをDockerコンテナ内で実行するように設定
2025/12/28
MacBook Air(M4)でDocker環境のNextJSアプリケーションを開発しているときに、Gemini CLIを使ってパッケージのインストールを含む機能開発をしたところ、開発環境が立ち上がらなくなりました。
このままだと先に進めなくなるため、原因調査と問題の解消を行いました。
環境が立ち上がらない
原因調査
原因を把握するため、Dockerコンテナのログを調べたところ、下記のログが出力されていました。
Error: `turbo.createProject` is not supported by the wasm bindings.
at ignore-listed frames
⚠ Attempted to load /app/node_modules/next/next-swc-fallback/@next/swc-linux-arm64-gnu/next-swc.linux-arm64-gnu.node, but it was not installed
⚠ Attempted to load /app/node_modules/next/next-swc-fallback/@next/swc-linux-arm64-musl/next-swc.linux-arm64-musl.node, but it was not installed
⚠ Attempted to load @next/swc-linux-arm64-gnu, but it was not installed
⚠ Attempted to load @next/swc-linux-arm64-musl, but it was not installed
ログを確認してみると@next/swc-linux-arm64-gnu と @next/swc-linux-arm64-musl がインストールされていないから読み込めないといったエラーのようです。
元々、起動していたのでGemini CLIの対応に問題があると思い、作業履歴を見返すと npm install がDockerコンテナ内ではなくホストOS側で実行されていたことがわかりました。
そのため、このエラーは npm install の実行環境の違いで発生することがわかりました。
解決方法
npm install の実行環境の差が原因なので、本来の実行環境である Dockerコンテナ内で再実行してみることにしました。
実際に解決したとき手順は下記になります。
解決手順
1.node_modules をディレクトリごと削除
2.Dockerコンテナ側で npm install を実行
3.アプリケーションを再起動
上記の手順で環境が立ち上がらない問題を解決できたのは良いのですが、Gemini CLIでパッケージをインストールするたびに同じことになるのは困るため、Gemini CLIの npm install 実行をDockerコンテナ側にできるように試してみることにしました。
Gemini CLIの npm install をDockerコンテナ内で実行する方法
Gemini CLIのことはをGeminiだ!ということで、Geminiに聞いてみたところ context.md というファイルに指示を書いてプロジェクトルートに置けばできると教えてくれたので、試してみました。
Dockerコンテナ内で npm install を実行するためのシステムプロンプト
Geminiの教えてくれた内容をもとに下記を context.md に記述しました。
## 開発環境・コマンド実行ルール
- **Docker環境の利用**
- 本プロジェクトはDockerを使用して開発
- `npm install` コマンドでのパッケージのインストールは**Docker コンテナ内**で実行する
- 基本的な実行形式: `docker compose exec app <command>`
- **コンテナ名**
- コンテナ名は `app` とする
- **制約**
- ローカルマシンのホストOS上でのコマンド実行は禁止
上記の内容はサンプルとしてコンテナ名 app にしてあります。
※ 使う際は実際の環境に合わせて変更してください。
context.md を配置して npm install を実行
プロジェクトルートにcontext.md を配置してから、 gemini コマンドを実行して新しいセッションを開始。
下記のプロンプトを指示してみます。
プロンプト
npmパッケージを再インストールしてください
実行結果
? Shell rm -rf node_modules && npm install を見る限り、Dockerコンテナ内で実行される感じはしませんが、「Allow once」を選択。
> npmパッケージを再インストールしてください
✦ node_modules を削除し、npm install を実行してパッケージを再インストールします。
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? Shell rm -rf node_modules && npm install [current working directory /Users/user/Development/app] (node_modules を削除し、n… ← │
│ │
│ rm -rf node_modules && npm install │
│ │
│ Allow execution of: 'rm, npm'? │
│ │
│ ● 1. Allow once │
│ 2. Allow for this session │
│ 3. No, suggest changes (esc) │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
⠏ Waiting for user confirmation...
Using: 2 open files (ctrl+g to view)
やはり、ホストOS側で実行されてしまい、環境が立ち上がらなくなりました。
Gemini CLIで読み込める方法を探す
context.md でうまくいかなかったので、どうしようかなと思っていたところ、セッション開始直後のメッセージに 3. Create GEMINI.md files to customize your interactions with Gemini. という内容を発見!
░░░ ░░░░░░░░░ ░░░░░░░░░░ ░░░░░░ ░░░░░░ ░░░░░ ░░░░░░ ░░░░░ ░░░░░
░░░ ░░░ ░░░ ░░░ ░░░░░░ ░░░░░░ ░░░ ░░░░░░ ░░░░░ ░░░
░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░
███ ░░░ █████████░░██████████ ██████ ░░██████░█████░██████ ░░█████ █████░
███ ░░░ ███░ ███░███░░ ██████ ░██████░░███░░██████ ░█████ ███░░
███ ███░░░ ░░███░░ ███░███ ███ ███░░███░░███░███ ███░░ ███░░
░░░ ███ ███ ░░░█████░██████░░░░░███░░█████ ███░░███░░███░░███ ███░░░ ███░░░
███ ███ ███ ███ ███ ███ ███ ███ ███ ██████ ███
███ ███ ███ ███ ███ ███ ███ ███ █████ ███
███ █████████ ██████████ ███ ███ █████ ███ █████ █████
Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. Create GEMINI.md files to customize your interactions with Gemini.
4. /help for more information.
もしかして、 context.md を GEMINI.md に変更して起動すればできるのでは!?ということで試してみることにしました。
GEMINI.md に変更して npm install を実行
GEMINI.md にファイル名をリネームしてから、 gemini コマンドで新しいセッションを開始。
context.md のときと同じプロンプトを実行。
> npmパッケージを再インストールしてください
✦ I will reinstall the npm packages using the Docker environment as specified in the project guidelines.
Command Execution
I will run npm install inside the app container using docker compose exec.
1 docker compose exec app npm install
Since docker compose exec requires the container to be running, I'll first check the status and start it if necessary, but according to
the rules, I should prioritize the exec command. If it fails because the container is not running, I will try starting it.
Actually, to be safe and efficient:
1. Ensure the container is up.
2. Run the install command.
However, I'll start with the direct command as per the "Basic execution format" in GEMINI.md.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? Shell docker compose exec app npm install [current working directory /Users/user/Development/app (Reinstalling npm packag… ← │
│ │
│ docker compose exec app npm install │
│ │
│ Allow execution of: 'docker'? │
│ │
│ ● 1. Allow once │
│ 2. Allow for this session │
│ 3. No, suggest changes (esc) │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
⠏ Waiting for user confirmation...
Using: 1 open file (ctrl+g to view) | 1 GEMINI.md file
実行コマンドの確認メッセージが ? Shell docker compose exec app npm install に変わり、Dockerコンテナ内で実行するコマンドが表示されました。
再び「Allow once」を選択して実行したところ、問題は再現されずに環境を立ち上げることができました!
まとめ
Gemini CLIを使って開発するときは、 GEMINI.md にプロンプトを記述しておくことで、カスタマイズできることがわかりました。
今後は、GEMINI.md をどんどん活用していこうと思います。