0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DockerHUBのDockerオフィシャルイメージでnpm -gな物などを入れようとするとエラー

Last updated at Posted at 2017-09-27

経緯

nodejsの環境をdockerに入れておこうとしたのですが
Angularのチュートリアルを入れようとしたところ

  • いつまでたっても終わらないインストール!
  • よく見たらループしてる!
gyp verb command install [ '8.6.0' ]
gyp verb install input version string "8.6.0"
gyp verb install installing version: 8.6.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.6.0
gyp verb ensuring nodedir is created /usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.6.0
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.6.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.6.0' ]
gyp verb install input version string "8.6.0"
gyp verb install installing version: 8.6.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.6.0
gyp verb ensuring nodedir is created /usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.6.0
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.6.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.6.0' ]
gyp verb install input version string "8.6.0"
gyp verb install installing version: 8.6.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.6.0
gyp verb ensuring nodedir is created /usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.6.0
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.6.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space

と、いう状態から見てみた結果、バッドな手段で動くようにしたメモ

調べてみる

該当のディレクトリを見てみたところ

root@d32b621e10b4:/# ls -l /usr/local/lib
total 8
drwxrwxr-x 3  500   500 4096 Sep 26  2017 node_modules
drwxrwsr-x 4 root staff 4096 Sep 13 12:33 python2.7

**UID/GID500なユーザーがOwner

そしてUID500なユーザーはいない…

root@d32b621e10b4:/# cat /etc/passwd |grep 500 |wc -l
0

しょうがないので…

/usr/local以下のOpenSSLも書き換わってしまうけれど…

きけんがあぶない

find / -uid |xargs chown node
find / -gid |xargs chgrp node

…とは考えたけど

  • uid500のユーザーを再定義してお茶を濁してみる
Dockerfile
FROM node:8.6

RUN apt-get update && apt-get install -y \
        apt-utils \
        curl \
        unzip \
        git \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN groupadd -g 500 nodeadm
RUN useradd -u 500 -g 500 -s /bin/false -m nodeadm

RUN mkdir -p /var/app

# RUN find / -uid 500 |xargs chown node
# RUN find / -gid 500 |xargs chgrp node

RUN chown -R node:node /var/app
# RUN chown -R node:node /opt/yarn
# RUN chown -R node:node /home/node

USER nodeadm

RUN npm install -g @angular/cli \
   && npm cache clean --force

USER node
WORKDIR /var/app

これで一応通る

+ @angular/cli@1.4.3
added 901 packages in 106.469s
npm info ok
npm info it worked if it ends with ok
npm info using npm@5.3.0
npm info using node@v8.6.0
npm WARN using --force I sure hope you know what you are doing.
npm info ok
 ---> 1c63a55ba5f9
Removing intermediate container 8f08b0230d3d
Step 9/10 : USER node
 ---> Running in fea0bdf40def
 ---> fd69d2a0028d
Removing intermediate container fea0bdf40def
Step 10/10 : WORKDIR /var/app
 ---> 33a466531277
Removing intermediate container 8c8c411ccf34

Successfully built 33a466531277
Successfully tagged node_angular:latest
Creating node_angular_1 ...
Creating node_angular_1 ... done
Attaching to node_angular_1
node_angular_1 exited with code 0

どうすればベスト?

  • そもそもglobalに入れているから/usr/local/libなどに書き込もうとして出る
  • -gは付けず作業ディレクトリに入れれば書き込まれない?
  • -gをつけないといけないようなものがないなら問題はない?
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?