LoginSignup
9
4

More than 3 years have passed since last update.

BEARアプリケーションのDocker開発環境構築例(docker-sync, Mutagen)

Last updated at Posted at 2020-12-22

はじめに

バックエンドの開発環境は Docker が主流になりつつあります 1 。私はローカルPCにPHPを直接インストールして使うのが好きですが、そうもいかないケースは多々あります。
BEAR.Sunday アプリケーションでは自動生成ファイルのI/Oが多いことから、Mac の Docker 環境だとパフォーマンスが問題となります。その解決例として、去年 Docker + BEAR.Sundayで開発するときはdocker-syncを使おう という記事を gamu1012 さんが投稿されていました。また、別の記事で、docker-sync が行うファイル同期は Mutagen でも実現が可能であることを私は知りました。 2
この記事では、BEARの開発環境を docker-sync と Mutagen を使ってそれぞれ構築したこと、両者は同等のパフォーマンスで高速であること、使用感について書きます。

検証環境

  • macOS Catalina プロセッサ 1.4GHz メモリ 16 GB
  • Docker Desktop v19.03.13 / docker-sync v0.5.14 / mutagen v0.12.0-beta2

docker-sync、Mutagen 環境の構築例

Mutagen 設定箇所

docker-compose.mutagen.yml

version: '3'

services:
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    expose:
      - '9000'
    volumes:
      - source-con-sun:/var/www/html/

  web:
    build: docker/nginx/
    ports:
      - '1758:80'
    volumes:
      - source-con-sun:/var/www/html/
    links:
      - app
    depends_on:
      - app

volumes:
  source-con-sun:

x-mutagen:
  sync:
    defaults:
      ignore:
        vcs: true
    source-con-sun:
      alpha: "."
      beta: "volume://source-con-sun"
      mode: "two-way-resolved"
      ignore:
        paths:
          - var/log/hal-app/last.logref.log
      configurationBeta:
        permissions:
          defaultFileMode: 0666
          defaultDirectoryMode: 0777
  • ボリュームマウント設定
  • x-mutagenフィールド追加

環境別BEARアプリパフォーマンス結果

BEARインストールデフォルトの index.php レスポンス時間:

Environment Time
Default Docker 1.10 sec
Docker + docker-sync 117 ms
Docker + Mutagen 162 ms
  • 指定したコンテキスト: hal-app
  • 測定手順等の詳細は上記リポジトリ参照

このように、docker-sync と Mutagen は、ほぼ同等で高速であることが分かりました。

Mutagen 使用時の問題点

  • Mutagen は起動時に1分ほど待たされる点がストレスに感じました。設定方法で改善できることなのかもしれませんが未調査です。また、絶対パスを含んだシンボリックリンクで同期エラーになるため、除外設定をしてやる必要がありました。 3

終わりに

上記の問題から、現時点では Mac の Docker ではやはり docker-sync が良いかなと私は思いました。
以上、BEAR.Sunday Advent Calendar 2020 12/22 の記事でした。良いお年を! :dolphin:

参照記事

※付記:homebrew での docker-sync インストール手順

本題と無関係ですが、私の環境だと docker-sync のインストールには手間取ったので、解決した方法を記しておきます。

brew install eugenmayer/dockersync/unox

時に下記のエラーが発生しました(Python 3.8 環境)。

The version of Python to use with the virtualenv in the `eugenmayer/dockersync/unox` formula\ncannot be guessed automatically because a recognised Python dependency could not be found.
If you are using a non-standard Python depedency, please add 
`:using => \"python@x.y\"` to\n`virtualenv_install_with_resources` to resolve the issue manually.

brew edit unox
として、
depends_on "python@3" を depends_on "python@3.8" に書き換えたらインストールができました。 4

9
4
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
9
4