Giter Club home page Giter Club logo

docker-unison's Introduction

Docker-Unison

A docker volume container using Unison for fast two-way folder sync. Created as an alternative to slow docker for mac volumes on OS X.

This image is trying to be as minimal as possible and it only weights 14.41MB.

The docker image is available on Docker Hub: registry.hub.docker.com/u/onnimonni/unison/

Usage

Docker

First, you can launch a volume container exposing a volume with Unison.

$ CID=$(docker run -d -p 5000:5000 -e UNISON_DIR=/data -v /data onnimonni/unison)

You can then sync a local folder to $UNISON_DIR (default value: /data) in the container with:

$ unison . socket://<docker>:5000/ -auto -batch

Next, you can launch a container connected with the volume under /data.

$ docker run -it --volumes-from $CID ubuntu /bin/sh

Configuration

This container has few envs that you can alter.

UNISON_DIR - This is the directory which receives data from unison inside the container. This is also the directory which you can use in other containers with volumes_from directive.

UNISON_GID - Group ID for the user running unison inside container.

UNISON_UID - User ID for the user running unison inside container.

UNISON_USER - User name for the sync user ( UID matters more )

UNISON_GROUP - Group name for the sync user ( GID matters more )

Docker Compose

If you are using Docker Compose to manage a dev environment, use the volumes_from directive.

The following docker-compose.yml would mount the /var/www/project folder from the unison container inside your mywebserver container.

mywebserver:
  build: .
  volumes_from:
    - unison
unison:
  image: onnimonni/unison
  environment:
    - UNISON_DIR=/var/www/project
    - UNISON_UID=10000
    - UNISON_GID=10000
  ports:
    - "5000:5000"
  volumes:
    - /var/www/project

You can then sync a local folder, using the unison client, to /var/www/project in the container with:

$ unison . socket://<docker>:5000/ -ignore 'Path .git' -auto -batch

You can use -repeat watch to sync everytime when files change:

$ unison . socket://<docker>:5000/ -repeat watch -ignore 'Path .git' -auto -batch

NOTE: In order to use -repeat option you need to install unison-fsmonitor.

Installing Unison Locally

Unison requires the version of the client (running on the host) and server (running in the container) to match.

Docker images are versioned with the version of unison which is installed in the container. You can use onnimonni/unison:2.51.2 image to use unison with 2.51.2 version.

  • 2.40.102 (available via apt-get install unison on Ubuntu 14.04, 14.10, 15.04)
  • 2.48.4 (available via apt install unison on Ubuntu 18.04)
  • 2.51.2 (available via brew install unison on Mac OS X) [default]

Additional versions can be added easily on request. Open an Issue if you need another version.

Installing unison-fsmonitor on OSX (unox)

# This is dependency for unox
$ pip install MacFSEvents

# unox is unison-fsmonitor script for Mac
$ curl -o /usr/local/bin/unison-fsmonitor -L https://raw.githubusercontent.com/hnsl/unox/master/unox.py
$ chmod +x /usr/local/bin/unison-fsmonitor

Credits

Thanks for leighmcculloch for showing me how to use unison with docker.

License

This docker image is licensed under GPLv3 because Unison is licensed under GPLv3 and is included in the image. See LICENSE.

docker-unison's People

Contributors

aaronjensen avatar lmillucci avatar onnimonni avatar scytacki avatar t-richards avatar villepietarinen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-unison's Issues

When the container is recreated with --force-recreate unison goes into corrupted state

If data container is reloaded unison can't continue properly.

Steps to reproduce:

docker-compose up -d
unison . socket://localhost:5000/ -auto -batch -prefer newer -repeat watch -ignore 'Path .git'
docker-compose up -d --force-recreate
unison . socket://localhost:5000/ -auto -batch -prefer newer -repeat watch -ignore 'Path .git'
# You should see errors about missing archives here now

Add support to unison 2.51.2

The default installed version for brew install unison on OS X is now 2.51.2. Can you please add the support for this version?

Unison incorrectly duplicates files/folders across multiple containers

We are seeing weird behaviour when setting up multiple docker environments with unison.

When switching between projects (with separate unison containers), the folders from one project would appear in the folder of another project. This is despite shutting down all current containers of 1 project before switching to another.

See attached docker-compose.yaml
screen shot 2017-04-05 at 11 23 05 am

Thanks to anyone with advice on this!

Port 5000 can cause problems with Kitematic

Kitematic has a hardcode list of 'web ports', and 5000 is on that list:
https://github.com/docker/kitematic/blob/e40ba41f1b2d623636241162df0b44178a685af6/src/utils/Util.js#L215

When you open a container with one of those ports exposed, Kitematic tries to open a Web Preview of the container. Sometimes this causes the unison container to crash.

Since the port 5000 seems arbitrary, perhaps it could be changed to something not in that list?
I looked here: https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers and see that 5000 is the default port of Flask which is probably why it is on the Kitematic list.

How about 5333 instead?
It is not assigned in IANA, and is not listed in the wikipedia list.

Does this actually work to improve performance?

It doesn't seem like this helps performance at all, as mounted volumes appear to be mounted volumes (aka slow)

# time dd if=/dev/zero of=test.dat bs=1024 count=100000
100000+0 records in
100000+0 records out
102400000 bytes (102 MB) copied, 29.7829 s, 3.4 MB/s

real    0m29.802s
user    0m0.260s
sys     0m2.640s

The actual container that is running unison is fast:

# time dd if=/dev/zero of=test.dat bs=1024 count=100000
100000+0 records in
100000+0 records out

real    0m0.267s
user    0m0.000s
sys     0m0.000s

But I can't figure out how to get that to translate over to any container that gets its volumes_from

Why not using unison only in docker

Why using a client/server between the host and docker ?
Unison could be launched inside the docker, synchronising an host mounted volume with your code and the internal app folder, or am I missing something ?

UNISON_VERSION not needed anymore

The origin version from used UNISON_VERSION but it seems, just to swap version. You do no longer need it, AFAICS, so i can happily remove it from the env vars in docker-sync, right? Thanks!

password

Trying to run this container and get prompted for a password change. Can the image have the password expiration turned off please?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.