Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker on OSX slow volumes

I'm trying to use docker beta on OSX, mainly for Symfony development but the mounted volumes are incredible slow. Even for a vanilla Symfony project I get 6s page load time. That's unbearable! Has anyone found a solution to this issue? Trying to move away from vagrant but I just can't find any reasonable way to work with docker instead.

like image 336
Viorel Avatar asked Jul 03 '16 08:07

Viorel


People also ask

Why is Docker so slow on macOS?

However, if you've ever encountered this on a macOS environment (Docker Desktop), you've probably noticed this to be quite slow at times. The main reason is how file synchronisation is implemented in Docker for Mac. Combined with PHP projects which use a lot of I/O, this can cause quite a performance hit.

How do I speed up Docker in OSX?

Ensure that you are using Docker Desktop version 4.6, available here. Navigate to 'Preferences' (the gear icon) > 'Experimental Features' Select the 'Use the new Virtualization framework' and 'Enable VirtioFS accelerated directory sharing' toggles. Click 'Apply & Restart'

Why is my Docker container so slow?

When you experience slow Docker performance, check your CPU, memory usage, and available disk space. Consider upgrading your system if a component does not perform as expected. When dealing with a specific container that is performing worse than expected, it may be helpful to check container-specific metrics.

Can I delete all Docker volumes?

You can clean up everything or clean up specific resources in Docker like images, container volumes, or the build cache. -a includes unused and dangling containers.


2 Answers

Okay the user Spiil gave a solution but I wanted to elaborate on the exact steps to take since I went through 12 hours trying to figure it out, but once you know how its super easy and fixes all the slow down issues!

The key here is to understand this solution creates NFS (Network File System) drives as the means of communication from the Docker Containers to your Mac instead of the standard OSX File System which is very slow currently either due to bugs or the way it works*

Follow these steps exactly.

1.) Clone this repo here (https://github.com/IFSight/d4m-nfs) in your home directory. To do this open up terminal and type cd ~

Then type git clone https://github.com/IFSight/d4m-nfs

Alternatively you can also do this in a one liner git clone https://github.com/IFSight/d4m-nfs ~/d4m-nfs

2.) Next go into the d4m-nfs folder and create a new file in the /etc folder and title it d4m-nfs-mounts.txt

3.) Add the following lines of code to this.

/Users/yourusername:/Users/yourusername:0:0 

What the above does is allows you to still use relative folders with docker-compose and allows all ports to connect on it hence the 0:0.

EDIT Do not put /Volumes here!!

4.) Go to your docker preferences and do the following

enter image description here

Make sure only /tmp is showing and NOTHING ELSE. I mean nothing else it won't work if there is anything else since it will create conflicts with the NFS systems that the script will make for you later. Restart docker and docker-compose down any containers as well.

5.) Finally navigate to the d4m-nfs directory we created in step 1 and type the following command, /bin/bash d4m-nfs.sh

edit The correct way to type the command above is this as another user from the github (if-kenn) pointed out, ./d4m-nfs.sh which uses the Shebang for what shell should run it.

If done correctly there should be no errors and this should work. Please note DO NOT RUN as sh d4m-nfs.sh this will create errors and you will have to delete your exports file to start over. In fact anytime you make any changes you will have to clear your exports file.

This is what mine looks like.

enter image description here

EDIT:: IMPORTANT -- Remove the /private and volumes! This should only be users/username now!

If you see anything other than this you were not running with bash. You can quickly get to the exports file like this in Mac if you make any errors and just clear it out to start over.

Just select go to folder

enter image description here

and then type /etc/exports

This is a nice shortcut to quickly get to it and clear it out in your favorite text editor.

Also make sure no containers are running or you will get the ........ loop of death. If this loop of death continues make sure you upgrade docker and then restart your computer. Yes restart... it seemed to be the only way to get it to work on my friends computer. Refer to this (https://github.com/IFSight/d4m-nfs/issues/3)

Note to .... loop. I recently found another solution. Make sure you are NOT logged as root, and make sure you pulled the git repo into your users ~ folder not the root ~ folder. In otherwords, it should be in Users/username.

Also, make sure /tmp folder has full write permissions since the script needs to write here or this won't work either. chmod 777 -R /tmp

6.) If you did it right when running the script it will look like this.

enter image description here

Then simply run your docker-compose up -d as usual in your symfony project folder (or whatever project you are using with docker) and everything should work... except NO MORE slow downs!

You will need to run this anytime you restart your computer or docker.

Also note if you get mounting errors showing up, you probably don't have your project stored in your Users/username directory. Remember that is where we mounted it. If your project is somewhere other than there you will need to modify the d4m-nfs-mounts.txt file accordingly.

Other Info:

enter image description here

like image 143
Joseph Astrahan Avatar answered Sep 27 '22 18:09

Joseph Astrahan


For people reading this now, maybe it's better to wait for Docker to fix this issue. A pull request has already been accepted to improve performance(https://github.com/docker/docker/pull/31047). This will be release somewhere in April 2017 and should be a big improvement.

I've tried some workarounds for Docker for Mac, but all of them had some pretty big disadvantages, mostly in usability. A good source for alternatives of the OSXFS can be found at: https://github.com/EugenMayer/docker-sync/wiki/Alternatives-to-docker-sync. Credits for Eugen Mayer for setting this up.

EDIT: First improvement is implemented in the edge release. https://github.com/docker/for-mac/issues/77 has more info on this.

like image 30
Frenus Avatar answered Sep 27 '22 17:09

Frenus