LoginSignup
11
2

More than 3 years have passed since last update.

Docker + BEAR.Sundayで開発するときはdocker-syncを使おう

Posted at

この記事について

BEAR.Sundayは依存関係などをコンパイルして保存するようになっています。

普段はこのおかげで高速に動作するのですが、

Docker for Mac はFILEのIOが遅く、Sundayのコンパイル結果を保存する処理、結果から読み戻す処理が致命的に時間がかかります。

開発効率をあげるために、どういう設定で利用するのが知りたかったため、各種方法を試し、計測結果をまとめた記事です。

docker-syncについて

コードをホストとコンテナ間で高速に同期させるためのツール

同期方法もrsyncやunisonなどが選択可能

インストール

gem install docker-sync
brew install eugenmayer/dockersync/unox
brew install fswatch unison rsync

run & stop

### run
docker-sync start
docker-compose up

### stop
docker-compose stop
docker-sync stop

設定ファイル

version: "2"
syncs:
  sync-volume:
    src: './'
    sync_strategy: 'unison'
    sync_excludes: ['.idea']
version: '3'

services:
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    expose:
      - '9000'
    volumes:
      - sync-volume:/var/www/html/:z

  web:
    build: docker/nginx/
    ports:
      - '1758:80'
    volumes:
      - ./public:/var/www/html/public:cached
    links:
      - app

volumes:
  sync-volume:
    external: true

詳細はリポジトリをご確認ください。

キャッシュオプションについて

cached

ホストの更新についてコンテナ反映時の遅延を許可する。

delegated

コンテナ内の更新についてホスト反映時の遅延を許可する。

詳細はこちら

計測方法

nginx + php-fpm のコンテナ環境でスケルトンからインストールした直後のBEAR.Sundayで行う。

実際に計測した設定などはこちらのリポジトリをご確認ください。

計測種別は4パターン

  • volume mountのオプションなし
  • volume mountのcachedオプションあり
  • volume mountのdelegatedオプションあり
  • unisonを利用したdocker-sync

処理にかかった時間の計測は実際の開発環境においての速度を測りたいため、nginxのrequest_timeとupstream_response_timeで行う。

結果

計測種別 request_time(s) upstream_response_time(s)
オプションなし 6.015 6.013
cached 2.850 2.849
delegated 2.945 2.943
docker-sync 0.290 0.288

まとめ

今回の条件だと圧倒的に docker-sync がはやかったです。

実際のプロジェクトでも試していますが、docker-sync がはやく、特に不便な点はありません。

少しだけインストールの手間はありますが、その価値は十分にあります。

またそれぞれの環境やどういうModuleを実装しているかによって結果は違うかと思いますので、是非お手元で計測してみてください。

参考リンク

Performance tuning for volume mounts (shared filesystems)
docker-sync
計測したコード

11
2
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
11
2