Speed up Docker for Mac with docker-sync

Dien Bui
2 min readMay 7, 2019

--

https://www.perforce.com/sites/default/files/image/2018-04/image-blog-docker-containers.jpg

Running webapp on Docker on MacOS can be quite slow, especially when you run multiple containers with file sync from host machine to containers. To help solve this problem when developing on MacOS, one of the solutions we can use is a tool called docker-sync.

This post will guide you step-by-step on how to setup on your local machine

WARNING: You should have experience with Docker and Docker Compose in advance so as to understand the post.

Pre-requisites

  1. Docker and Docker Compose must be installed
  2. A Docker image of your project
  3. Ruby is installed

Setup

1/ Install docker-sync

gem install docker-sync --no-rdoc --no-ri
docker pull eugenmayer/unison:2.51.2.1

2/ Create docker-sync.yml in the main directory of your project and include the following config in the file.

3/ Create docker-compose-dev.yml in the main directory

Imagine you have docker_compose.yml like this and you want to sync file to webapp folder in rails_server with docker-sync

First of all, remove line no 5 and 6 (they are the cause of slow container). Then add the following config to the docker-compose-dev.yml file

4/ Start docker-sync

docker-sync start

If you want to stop then replace start with stop . To clean up log and reset docker-sync, use clean .

5/ Start containers with Docker Compose

docker-compose -f docker-compose.yml -f docker-compose-dev.yml up -d

To check if everything is running properly, run docker ps and check for the containers names with app-code-sync and rails_server . If they exist then hooray, your app is now up and running with docker-sync.

Note: you may want to set alias in .bashrc/.zshrc the command above for faster typing.

Extra reading

For source code, go to the GitHub repo

For deeper understanding and configuration, remember to visit the wiki

--

--

Dien Bui

Backend, data and cloud computing enthusiast | Power of open-source and sharing believer | GitHub: https://github.com/joebui