Change storage driver for Docker on OS X

2019-01-23 19:18发布

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?

3条回答
等我变得足够好
2楼-- · 2019-01-23 19:46

Even when using docker-for-mac you still have a virtualization under OSX using hyperkit/xhyve, since the Darwin kernel does still not run docker "natively". Thus you cannot chose a storage-driver like you actually are supposing. Also read the last bulletin point here https://docs.docker.com/docker-for-mac/docker-toolbox/#/the-docker-for-mac-environment

At installation time, Docker for Mac provisions an HyperKit VM based on Alpine Linux, running Docker Engine. It exposes the docker API on a socket in /var/tmp/docker.sock

On docker-for-mac OSXFS is used to share your OSX local folders to the xhyve slim vm so the linux kernel/os(alpine) picks those up while starting the containers and binding any volumes to the 'vms file system' which is then synced.

AFAIK there is no way to chose the storage driver under docker-for-mac, since it is not possible due to the way OSXFS syncs from the host to the alpine-vm which then offers this to the containers.

查看更多
冷血范
3楼-- · 2019-01-23 19:52

Matt is correct that the default Docker-for-Mac kernel doesn't support devicemapper, but in general, there's a better way to change the daemon options:

Start Docker for Mac. Click the whale in the menu bar, then click Preferences

the docker whale menu, with the preferences option highlighted

Click the Daemon icon in Docker for Mac Preferences

Click Advanced and provide the JSON for customizing your daemon settings.

The Docker Preferences Dialog under Daemon/Advanced

Then click Apply & Restart, and check the change:

$ docker info | grep Stor
Storage Driver: overlay2
查看更多
爷、活的狠高调
4楼-- · 2019-01-23 20:10

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.

查看更多
登录 后发表回答