File Synchronization on Mac

To work with an IDE like phpstorm or eclipse on your host system you need to sync your code into the container. The integrated file sharing solution from docker cannot be used because of very bad performance.

To have a good performance we need to sync the files from the host system into the container.

For the two way file-synchronization we use the great tool Unison.

Setup Unison on Mac

To work with Unison it's very important to have the right versions installed.

Please follow the instructions step by step.

Step 1: Download and Install Unision

Download and install Unision by Drag'n Drop into Application folder

Download Unsion

Step 2: Install Unison command-line tool

Click on "Yes" to install the Unison command-line tool

Unison command line tool

Step 3: Open terminal and install xcode, pip and macfsevents which are needed for unison-fsmonitor

xcode-select --install
sudo easy_install pip
sudo pip install macfsevents

Step 4: Install unison-fsmonitor binary

sudo curl https://db5iu3k4j1efi.cloudfront.net/unison-fsmonitor-IKzJ1fQDsA. > /usr/local/bin/unison-fsmonitor && chmod 775 /usr/local/bin/unison-fsmonitor

Step 5: Create a sync.sh file for each project you want to sync

In our example we want to sync the files from our host system into the container from

/Users/stefan/PhpstormProjects/magento2.dev/

to

/home/cloudpanel/htdocs/magento2.dev

For this we create the file:

/Users/stefan/PhpstormProjects/magento2.dev/bin/sync.sh

with the following content:

#!/bin/bash
#rm -rf /Users/$(whoami)/Library/Application\ Support/Unison/*
unison -repeat watch /Users/stefan/PhpstormProjects/magento2.dev/ ssh://root@127.0.0.1//home/cloudpanel/htdocs/magento2.dev/ -ui text

Make sure the sync.sh file is executeable.

To make it executeable just run: chmod 775 sync.sh

Step 6: Start file-synchronisation

To start the file synchronisation execute the sync.sh file

./sync.sh

Unison Sync

Enter the password "root" to start the file-synchronization

Troubleshooting

If you see the error message "Fatal error: inconsistent state. The archive file is missing on some hosts" please do the following:

Unison Inconsistent State

1) Delete unison archives on host system with the following command

rm -rf /Users/$(whoami)/Library/Application\ Support/Unison/*

2) Delete unison archive in container

ssh root@127.0.0.1 rm -rf /root/.unison

3) Start sync process again