7
5

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.

Dockerコンテナのマウントディレクトリでnpm installが遅い

Posted at

Github上でも議論されていました。

私の環境では、Dockerコンテナの/tmp上で npm install を実行した後、node_modulesのsymlinkをアプリのディレクトリに設定することで動作を速くすることができました。検証結果を共有します。

改善前:

$ cd /mnt/app && npm install

改善後:

$ cp /mnt/app/package.json /tmp/.
$ cd /tmp && npm install
$ ln -s /tmp/node_modules /mnt/app/.

環境

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11.6
BuildVersion:   15G31

$ vboxmanage --version
5.0.24r108355

$ vboxmanage showvminfo default | grep -E '(CPU|Memory)'
Memory size:     2048MB
CPU exec cap:    100%
Number of CPUs:  2
CPUID Portability Level: 0
CPUID overrides: None

$ docker -v
Docker version 1.11.2, build b9f10c9

$ docker-machine -v
docker-machine version 0.7.0, build a650a40

$ node -v
v4.4.7

$ npm -v
2.15.8


検証

検証プロジェクトとして、Material UIのdocsを使います。

$ git clone git@github.com:callemall/material-ui.git
$ cd material-ui/docs

ローカルディレクトリ

結果: 約3分

$ rm -rf node_modules
$ time npm install
...
npm install 148.11s user 51.25s system 117% cpu 2:50.11 total

Docker:マウントディレクトリ

結果: 約16分

$ rm -rf node_modules
$ docker run --volume $(pwd):/mnt/app -it node:4.4 bash

root@6d7dba381d3a:/# cd /mnt/app
root@6d7dba381d3a:/mnt/app# time npm install
...
real    15m55.132s
user    5m29.150s
sys     16m18.160s

Docker:/tmp

結果: 約4分

$ rm -rf node_modules
$ docker run --volume $(pwd):/mnt/app -it node:4.4 bash
root@65b6a6c739d5:/# cp /mnt/app/package.json /tmp/.
root@65b6a6c739d5:/# cd /tmp
root@65b6a6c739d5:/tmp# time npm install
...
real    4m4.300s
user    2m16.840s
sys     2m4.350s
7
5
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
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?