0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Debian + Docker環境でpm2のインストール時に「getaddrinfo EAI_AGAIN registry.npmjs.org」エラーが発生する場合の対処法

Posted at

背景

VPS上で稼働しているDebian+Docker環境において、 docker compose build 実行時にnode.jsのプロセスマネージャーpm2をグローバルインストールしようとしたところ、 getaddrinfo EAI_AGAIN registry.npmjs.org エラーが発生した。

docker compose build
# FROM node:22.18-slim
...
 > [ 7/11] RUN npm install -g pm2:
71.04 npm error code EAI_AGAIN
71.04 npm error syscall getaddrinfo
71.04 npm error errno EAI_AGAIN
71.04 npm error request to https://registry.npmjs.org/pm2 failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org
71.04 npm error A complete log of this run can be found in: /root/.npm/_logs/2025-08-11T06_41_13_651Z-debug-0.log
------
WARNING: current commit information was not captured by the build: failed to read current commit information with git rev-parse --is-inside-work-tree

Dockerfile:35

--------------------

  33 |     

  34 |     # Install PM2 globally

  35 | >>> RUN npm install -g pm2

  36 |     

  37 |     # switch non-root user

--------------------
...

原因を調べてみたところ、ドメイン名の名前解決にIPv6を使用しており、IPv6での外部通信に失敗している可能性が高そうだった。

# (一部伏せ字)
$ cat /etc/resolv.conf
nameserver 24XX:XXXX:XXXX:XXXX::11
nameserver 24XX:XXXX:XXXX:XXXX::12
$ docker network inspect bridge
[
    {
        ...
        "Driver": "bridge,
        "EnableIPv4": true,
        "EnableIPv6": true,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                },
                {
                    "Subnet": "fdXX:XXXX:XXXX::/64",
                    "Gateway": "fdXX:XXXX:XXXX::1"
                }                
            ]      
        },
        ...

当該環境はファイアーウォール(FW)設定に ufw を使用しており、HostのFW設定とDockerのFW設定が入り混じっている。

影響を鑑みてFWの設定変更を行わずに、どうにかIPv4とIPv6を両対応させようと試みたが、DockerがIPv6有効のままだとビルドエラー解消ができなかったため、最終的にDockerについては一旦IPv4で名前解決を行う形にした。

sudo vim /etc/docker/daemon.json
/etc/docker/daemon.json
{
  "dns": ["1.1.1.1", "1.0.0.1"]
}
sudo systemctl restart docker

Dockerのネットワーク設定を再度確認。

$ docker network inspect bridge
[
    {
        ...
        "Driver": "bridge",
        "EnableIPv4": true,
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },

"EnableIPv6": false になっていることを確認して、再度 docker compose build を実行。

docker compose build
...
=> [ 7/11] RUN npm install -g pm2                       7.3s
...

無事エラー解消できた。

当面はこれでしのぐことにする。

また新しい環境を構築する際はIPv6にもチャレンジしてみたい。

メモ:実行環境

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

$ docker -v
Docker version 28.3.2, build 578ccf6

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?