Search code examples
macosdockerosx-elcapitan

Change storage driver for Docker on OS X


This is basically a follow-up to this question, but now since the OS X Docker no longer needs Docker Toolbox (i.e. no longer needs VirtualBox), I'm totally lost how to switch from AUFS to devicemapper or something else.

The issue I'm facing here as well is the missing hardlink support in AUFS which makes problems during the installation of the Android SDK, so I hope devicemapper will help me here.

So, how can I change the storage driver of Docker's native implementation in OS X?


Solution

  • The Alpine Linux VM that Docker for Mac runs doesn't support the devicemapper driver but it can run the overlay2 driver.

    There's no UI for managing this config yet The Docker for Mac UI has been updated to include a "Daemon" section where you can edit the docker.json config file.

    Got to the Docker icon > "Preferences" > "Daemon" > "Advanced" and set the storage-driver to overlay2

    { "storage-driver": "overlay2" }
    

    See kojiros answer for full step by step details.

    Manual Config Editing

    You can modify the Docker config files on your mac in ~/Library/Containers/com.docker.docker/Data/database.

    This directory is a git repo and it will normally be blank:

    $ cd ~/Library/Containers/com.docker.docker/Data/database
    $ ls -al
    total 0
    drwxr-xr-x   4 user  staff  136 28 Sep 02:46 .
    drwxr-xr-x  20 user  staff  680 28 Sep 02:54 ..
    drwxr-xr-x  11 user  staff  374 28 Sep 02:58 .git
    

    There are files in the git database though

    $ git status
    On branch master
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    
        deleted:    com.docker.driver.amd64-linux/etc/docker/daemon.json
        deleted:    com.docker.driver.amd64-linux/etc/hostname
        deleted:    com.docker.driver.amd64-linux/etc/sysctl.conf
    ....
    

    To retrieve the previous contents from git, run:

    $ git reset --hard HEAD
    

    Edit the docker daemon config file that now exists, to include the overlay2 storage driver.

    $ vi com.docker.driver.amd64-linux/etc/docker/daemon.json
    

    Docker on the VM will need most of /var/lib/docker removed before you can start with a new storage driver. This will DELETE all of your containers, images and volumes! Take backups of anything you need beforehand.

    Attach to the VM's tty with screen (brew install screen if you don't have it)

    $ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
    

    Login with root, no password

    moby:~# /etc/init.d/docker stop
    moby:~# rm -rf /var/lib/docker/*
    

    Exit the prompt with ctrl-d

    Exit the screen session with ctrl-a then d

    Now you can commit your changes back on the mac

    $ git commit -m overlay com.docker.driver.amd64-linux/etc/docker/daemon.json
    

    Changes will be picked up automatically by Docker on commit and the VM will be restarted.

    You now have a Docker for Mac VM running with the overlay2 storage driver. If that doesn't resolve your problems, with some work you could probably figure out how to get devicemapper support working in the VM too. The steps once you've figured that out are all the same.

    Note Upgrades to Docker for Mac can cause some weirdness. Last upgrade all my containers/images disappeared from a docker ps or docker images. I had to reset the git repository again and restart Docker for my config changes to come back, then all the data came back.