Performance: docker-sync for Mac
To improve the performance of docker on MacOS, we tried docker-sync,see http://docker-sync.io/
One-time work: install docker-sync with gem install docker-sync
see also https://docker-sync.readthedocs.io/en/latest/getting-started/installation.html
The idea: don't touch the original docker-compose.yml and use overrides on MacOS for the definition of the volumes, which will be synced by docker-sync instead of docker itself.
For this, we need two .yml files: the definition for docker-sync (docker-sync.yml) and the MacOS overrides (docker-compose.mac.yml) for docker-compose.
The configuration file for docker-sync is docker-sync.yml
:
version: "2"
syncs:
PROJECTNAME-docker-sync:
src: './'
sync_userid: '501'
sync_excludes: ['.docker-sync','.gitignore','.git/','.idea/','.DS_Store','.notifier']
volumes:
- PROJECTNAME-docker-sync:/var/www/html
Explanation:
- the docker-sync.yml file has to be placed in the root directory of the project
- for PROJECTNAME, use the name defined by the l3d project installation
- sync_userid: '501': 501 is the id of logged in user and can be obtained with
id -u
- the excludes are from example-yml files and are subject to change/expand
For docker-sync (must be executed in the same directory, where the docker-sync.yml file resides) there are (mainly) three options:
-
docker-sync start
: start syncing in the background, imporant: first run can take up to 10(!) minutes for initialization -
docker-sync stop
: stop syncing by stopping the background process -
docker-sync clean
: use this only after you are done with the project and want to free up space, the sync containers and volumes will be released
The docker-compose overrides for MacOS, the file docker-compose.mac.yml
:
version: "3"
services:
php:
volumes:
- PROJECTNAME-docker-sync:/var/www/html:nocopy
apache:
volumes:
- PROJECTNAME-docker-sync:/var/www/html:nocopy
volumes:
PROJECTNAME-docker-sync:
external: true
For PROJECTNAME, again, use the name defined by the l3d project installation.
To use the "override" functionality of docker-compose, use the following line to start the containers:
docker-compose -f docker-compose.yml -f docker-compose.mac.yml up -d
(Annotation: for *nix-systems, the containers will be started with: docker-compose -f docker-compose.yml up -d
)
Rules for the start/stop order:
- execute docker-sync start before running docker-compose up
- execute docker-sync stop after running docker-compose stop
- (execute docker-sync clean after running docker-compose down)
TODO for l3d (or d4d?) when executing composer install --dev
:
- create the configuration files docker-sync.yml and docker-compose.mac.yml (inject PROJECTNAME and user-id)
- execute docker-sync start before starting the containers with docker-compose
- override docker-compose volume definition by adding docker-compose.mac.yml as described above
- execute docker-sync stop after stopping the containers
Side remark and not related to docker-sync:
In our tests we realized, that port 8000 is often used by other programs eg Bootstrap Studio, so it would be a nice feature if the port of traefik will be configurable.