Seite wählen

Docker on OSX

von | Mai 19, 2016 | Container, Mac

DockerLogoRunning Docker on OSX can be made possible using different methods:

Docker containers require kernel features which are only available in modern Linux kernels. In order to run Docker on OSX for example, one needs a virtual machine with a smallish Linux running in it.

Docker for Mac Beta

Docker for Mac uses xhyve, a lightweight OS X virtualization solution built on top of Hypervisor.framework. This requires you to run OS X 10.10 Yosemite and higher. The VM is provisioned with Alpine Linux running Docker engine.
The Docker API is exposed in /var/run/docker.sock where the docker and docker-compose CLI commands may directly communicate with. This is one of the benefits compared to Docker machine, especially when you do not need to manage your docker VM, or set specific environment variables before running it. Docker for Mac is further installed as native OSX application and only provides symlinks to /usr/local/bin/{docker,docker-compose}.
After the app is installed, I only had to manually add the bash-completion provided by Homebrew.

cd /usr/local/etc/bash_completion.d
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion

I was granted a beta access key for Docker for Mac today 🙂 Even if this is still beta, it already feels much more integrated into my test and development workflow rather than using Docker machine. Awesome job! 🙂


 

Docker Machine

Docker machine will use Virtualbox as VM provider. In order to avoid manual interaction in each terminal I’m opening I’ve added an alias into my bashrc file.

vim $HOME/.bashrc
alias enable_docker=". '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh'"

This script doesn’t do much except for starting the VM using the Virtualbox cli tools and then source the exported variables into your current shell environment. That way the docker client will be able to communicate with the docker daemon running inside the VM.

Parallels instead of Virtualbox

While Virtualbox works fine there are significant performance improvements when using Parallels on OSX. Furthermore it is reasonable to only use one application firing virtual machines (the Icinga Vagrant boxes also provide support for Parallels as Vagrant provider).
I was therefore looking for a native Parallels driver for Docker. Following this issue shed some light on the history of Docker drivers and their support as plugins. Parallels doesn’t seem to be officially supported by Docker themselves according to their documentation. Though there is an official driver plugin from Parallels themselves which works for Pro and Business subscriber editions only. The main reason seems to be the limited cli features in the Standard edition.

Requirements for Parallels

The main requirement is at least Docker 1.9.1 providing the Docker toolbox 0.5.1+.

Installation

I’m using Homebrew, the manual installation parts are described in the documentation. Brew tries to pull docker-machine as well – if you’re using the version from docker.com you can safely ignore the linking error.

brew install docker-machine-parallels

Create a docker machine

docker_machine_parallels_runUse the driver „parallels“ and add the name „docker-parallels“. This will create a new Parallels VM with 20GB HDD and 1GB RAM by default. In case you want to disable sharing the /User mounts, add –parallels-no-share.

docker-machine create --driver=parallels docker-parallels

Add the environment variables to your shell and run docker pulling the latest Fedora container.

eval $(docker-machine env docker-parallels)
docker run -ti fedora:latest bash

Automate it

I’ve partially modified the Docker toolbox script in order to support Parallels.

wget https://raw.githubusercontent.com/dnsmichi/docker-tools/master/toolbox/scripts/osx/start.sh -O /usr/local/bin/enable_docker
chmod +x /usr/local/bin/enable_docker
enable_docker

 

Conclusion

While the Docker Machine integration allows room for improvement the Parallels driver works like a charm. Though I have to admit – while looking into the Parallels integration, Docker announced Docker for Mac and I was eagerly waiting for it.
Both methods are working, but the Docker for Mac application integrated natively into OSX is pretty slick. I like it a lot!
If you are looking for more Docker and its many possibilities – follow our blog closely and visit the Docker training sessions 🙂

0 Kommentare

Einen Kommentar abschicken

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Mehr Beiträge zum Thema Container | Mac

NWS-ID for your Managed Kubernetes!

First Cloud, now Kubernetes - the integration of NWS-ID with our portfolio continues! As a next step, we will merge your Managed Kubernetes clusters with NWS-ID. Credit goes to Justin for extending our cluster stack with OpenID-Connect (OIDC), the base for NWS-ID! How...