7
12

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 3 years have passed since last update.

Docker x Laravel めちゃくちゃ遅い Docker for Windows を爆速化する

Posted at

@ucan-labさんのDocker x Laravel めちゃくちゃ遅い Docker for Mac を爆速化するの案4をWindows10で検証しました。

案4. ボリュームマウントを使う

vendorやnode_modulesのデータを名前付きボリュームに格納して、ホスト側とコンテナ側と分離して管理する案。
同期処理が発生しないので、その分速くなる。

docker-compose.ymlにボリュームマウントの設定を追加して、composerとnpmのインストールを比較します。この記事ではなぜ早くなるかは触れません。

結果

composer installnpm installの速度をそれぞれ比較しています。

$ time composer install
real    6m26.446s  -> 0m57.445s  # 6.7倍
user    0m9.375s   -> 0m3.035s
sys     0m51.148s  -> 0m1.544s

$ time npm install
real    1m31.764s  -> 0m22.720s  # 4.0倍
user    0m46.022s  -> 0m23.705s
sys     0m32.465s  -> 0m13.917s

Windows10環境では4~7倍速くなりました!
参照元のMacのように20倍とはいきませんでしたが、数行の追加だけで十分早くなって満足です!

環境

ホストOSの環境

  • Windows 10 Home バージョン2004(OSビルド 19041.508)
  • WSL2 (Ubuntu 20.04.1 LTS)
  • Docker version 19.03.13, build 4484c46d9d
  • docker-compose version 1.27.4, build 40524192

環境構築には下の記事が参考になります。
Windows Subsystem for Linux Installation Guide for Windows 10
Windows 10 Home で WSL 2 + Docker を使う | Qiita

コンテナ

Laravel + Nginx + MySQLの開発環境を使って検証します。
詳しくはブログで公開しています。

  • php (php-fpm) 7.4.1
    • composer 1.10.13
    • nodejs v12.18.4
    • npm 6.14.6
    • Laravel 8.8.0
  • mysql 8.0
  • nginx 1.19.2

composerとpackage.jsonは、プロジェクト作成からlaravel/jetstreamのInertiaをインストールしたところまでの状態です。

検証するdocker-compose.yml

コメントadd行の有無で速度を比較しています。


version: '3'

volumes: # add
  vendor-store: # add
  node_modules-store: # add

services:
  php:
    container_name: php
    build: ./docker/php
    volumes:
    - ./web:/var/www
    - vendor-store:/var/www/laravel/vendor # add
    - node_modules-store:/var/www/laravel/node_modules # add
    environment:
      TZ: Asia/Tokyo

  nginx:
    image: nginx
    container_name: nginx
    ports:
    - 80:80
    volumes:
    - ./web:/var/www
    - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
    - php

  db:
    image: mysql:8.0
    container_name: db
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: database
      MYSQL_USER: docker
      MYSQL_PASSWORD: docker
      TZ: 'Asia/Tokyo'
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    volumes:
    - ./docker/db/data:/var/lib/mysql
    - ./docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
    - ./docker/db/sql:/docker-entrypoint-initdb.d
    ports:
    - 3306:3306

実行手順は参照元と同等です。パスを読み替えてください。

7
12
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
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?