docker on OSX slow volumes

前端 未结 10 1520
无人共我
无人共我 2021-02-02 08:24

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. Th

相关标签:
10条回答
  • 2021-02-02 08:54

    Apparently there is a workaround at the moment:

    https://forums.docker.com/t/file-access-in-mounted-volumes-extremely-slow-cpu-bound/8076/48 https://forums.docker.com/t/how-to-speed-up-shared-folders/9322/15

    0 讨论(0)
  • 2021-02-02 08:54

    I spent a lot of my time in searching viable solution. And I found. d4m-nfs allow you use docker volumes via nfs. In my case it gave increase performance 16 times! (1.8sec vs ~30sec)

    Also d4m-nfs has quite a intricate manual, so here is another link with detailed example: https://github.com/laradock/laradock/issues/353#issuecomment-262897619

    I just leave this here for other googlers.

    0 讨论(0)
  • 2021-02-02 08:54

    We overcame this issue by synchronizing the local and the docker for mac filesystem using syncthing. We built an open source tool that follows this approach, in case it helps: https://github.com/okteto/cnd

    0 讨论(0)
  • 2021-02-02 08:56

    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

    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.

    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

    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.

    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:

    0 讨论(0)
提交回复
热议问题