/lsyncd

Dockerfile for the Live Syncing Daemon.

Primary LanguageShell

Lsyncd Dockerfile

Dockerfile for the Live Syncing Daemon.

This Docker image is intended to improve file system performance on Docker for Mac by syncing host mounts with named volumes.

This only provides one-way-sync.
For setups that only occasionally require a reverse sync, a sample approach is provided in the Reverse sync section.
For setups that require two-way-sync, please have a look at docker-sync.

See also: Performance tuning for volume mounts

Usage

With Docker Compose

See the sample docker-compose.yml.

Without Docker Compose

Create a named volume:

docker volume create html

Start lsyncd to sync the host directory with the named volume:

docker run \
  -d \
  -v "$PWD/html:/mnt/html" \
  -v html:/var/www/html \
  --name lsyncd \
  allthings/lsyncd \
  -rsync /mnt/html /var/www/html

Start a web server using the named volume:

docker run \
  -d \
  -v html:/var/www/html \
  -p 80:80 \
  --name web \
  php:apache

Add and remove files in the html directory and reload http://localhost/ to see them being synced with the named volume.

To remove the containers and the named volume, execute the following:

docker rm -vf lsyncd web
docker volume rm html

Lsyncd documentation

For additional documentation, e.g. how to sync multiple directories or how to use a config file to apply rsync options, please consult the lsyncd manual.

Performance comparison

Start up the container set:

docker-compose up -d

Generate some extra data by duplicating this file into the html directory:

seq -f %04g 1000 | xargs -I% cp README.md html/%.md

Run a benchmark against the web server using a standard host mount:

docker-compose exec web ab -n 100 web2/

Run a benchmark against the web server using a synced named volume:

docker-compose exec web2 ab -n 100 web/

Remove the generated data:

rm -rf html/*.md

Stop the container set:

docker-compose down -v

Reverse sync

To sync files back from the named volume to the host mount, a sample shell script is provided, that stops lsyncd, syncs the given directories and restarts lsyncd again.

It can be used the following way:

./lsyncd-rsync.sh /var/www/html/ /mnt/html/

Please note that the trailing slashes are required by rsync, which is used for the synchronization.

License

Released under the MIT license.