LoginSignup
27

More than 3 years have passed since last update.

dockerでyarn addすると遅い問題を改善する

Last updated at Posted at 2018-10-01

概要というか結論

dockerで作った開発環境でyarn addをする時はcacheディレクトリもvolumesに指定しましょう。

キャッシュの指定方法

まず、yarnのキャッシュディレクトリを調べます。

docker-compose run app yarn cache dir

表示されたディレクトリをvolumesで指定します。

docker-compose.yml
version: '3'

services:
  app:
    image: node:alpine
    volumes:
      - .:${PWD}
      - yarn-cache:/usr/local/share/.cache/yarn/v2
    working_dir: ${PWD}

volumes:
  yarn-cache:

計測してみる

適当にyarn addをして計測してみます。

test.sh
docker-compose run app yarn init -y
docker-compose run app yarn add -D firebase-tools
docker-compose run app yarn add vue

volumesなし

volumesを指定しないとこんな感じです。
2つ目のyarn addはvueをインストールしただけなのに遅いですね。

Done in 25.24s.
Done in 15.61s.

volumesあり

一旦ファイルを削除しvolumesを指定します。
再度テストしたところ2つ目のyarn addが明らかに速くなりました。

Done in 22.69s.
Done in 2.99s.

その他

ちなみにnpmの場合はキャッシュ用にvolumesを用意しなくても、2つ目のインストールの速度は低下しませんでした。
が、やっぱりyarnの方が速いですね。

37.196s
5.472s

参考

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
27