May 19, 2015 - Docker runs your code in a container, which is like a lightweight VM. Instead, you have to run Linux in a VM (which is why on OS X, instead.
Sun, Mar 27, 2016A few days ago, Docker has announced a closed BETA program for their newapplications “Docker for Mac” and “Docker for Windows”. These apps are meant tosimplify the usage of Docker containers for every developer even more. They tryto lower the barrier to install and use Docker on your desktop and laptop computersfor both Mac and Windows users.
As soon as I received the first rumors that there is a special feature built-in,which should also simplify the developers workflow for IoT applications, I was gettingtotally thrilled and registered immediately for the BETA program. It was really hardto wait for, but luckily I’ve received an email with my BETA invitation and accesstoken within a few hours only.
Here I’d like to give you a first insight view how to install and use “Docker for Mac”with a basic walk-through on my MacBook Pro running the very latest OS X 10.11.4.
So, please join me on this journey…
Access to the BETA program
You can easily register to the Docker BETA program at https://beta.docker.com. Onceyou’re logged in with your Docker ID (which is literally your Docker Hub user account)you can apply for testing “Docker for Mac” and “Docker for Windows”.
As this is a closed BETA, you’ll get on a waiting list and hopefully will be selectedsoon. So, please be patient until you’ll receive an invitation email with some moredetailed instructions and a personal access key.
For this blog post, I’ll show you how easy it is to install and use Docker on OS X.And I guess, we’ll write another post later for all the curious Windows users, too.
Download and install “Docker for Mac”
When you’re selected for the BETA, you’ll receive an email titled “Docker Private Beta”with a link to the download page and an access key.
Download the installer package called “Docker.dmg” to your Mac and double click it,drag and drop the “Docker beta” app to your Applications folder.
Now, from your Lauchpad you can start the “Docker beta” app directly the first timeand you can begin right away using Docker on your Mac.
Once you start the BETA Docker app the first time you’ll be asked to enter yourpersonal invite token.
Token has been accepted.
The Docker app needs to additionally install a network helper and requests for privilegesto do so.
Enter your credentials to grant privileged access.
Success, the Docker app is installed and you can easily find and access it byclicking on the little neat whale icon.
Using “Docker for Mac” the first time
To use Docker we’ll just start a terminal window and use the Docker CLI to accessthe local Docker Engine.
First, get the version of the Docker command:
Determine the versions of the Docker Client and the Docker Engine:
Display some more detailed informations about the installed Docker software:
Let’s start a real Docker container
First, we’ll check how our host operating system looks like:
000bAs already expected we see our host OS is OS X or
Darwin
with a kernel version 15.4.0
. Our CPU architecture is x86_64
, which indicates that we’re running on an Intel-based64-bit CPU.000bSecond, let’s start a basic Linux container and here we’re using a Debian standard distrofor now. This will take a few second because the Docker Engine has to fetch/downloadthe Docker image
debian
from the Docker Hub.![Windows Windows](/uploads/1/2/5/7/125790462/449854904.jpg)
As you can see, we now do have an interactive bash prompt within a running DebianLinux container.
I’d like to start a really tiny Linux container next, which starts evenfaster than Debian. Alpine Linux is meant to be super-small and it brings a lotof advantages into the container world, too.
Starting an interactive Alpine container is pretty much the same as Debian, but wehave to use a Bourne shell instead of bash.
As you can see, this container is running on the same kernel version like before, butuses a completely different Linux distribution.
Now, let’s look at the details of these both Docker containers. Both are completeLinux systems, but with a substantial difference in size.
Alpine Linux is damn small in size and thus the Docker images built upon Alpineare extremely small as well, and much faster to download. Another major advantage is thesecurity model of Alpine Linux, which reduces the attack surface dramatically andprovides faster and easier security updates as well.
This experiment with “Docker for Mac” clearly demonstrates that we can run Linuxcommands inside Docker containers with a Linux OS and a recent kernel version 4.1.19. This is indeed different to our host operating system OS X.
That’s pure Docker container magic: running a Linux container seamlessly on ourdevelopment machine, here on a MacBook Pro (Retina, 15-inch, Mid 2014).
The Magic behind the scenes
As I’ve shown you in the screenshots above, our host operating system, where the DockerClient is running, is
darwin/amd64
or OS X, but the Docker Engine runs on linux/amd64
.Maybe you’re wondering how this even can be possible, right?
The answer is quite easy, “Docker for Mac” is shipping it’s own lightweight hypervisorcalled xhyve, which itself is a port of the BSD hypervisorbhyve to OS X.
The answer is quite easy, “Docker for Mac” is shipping it’s own lightweight hypervisorcalled xhyve, which itself is a port of the BSD hypervisorbhyve to OS X.
The engineers at Docker have greatly enhanced xhyve to enable an optimized usageto efficiently run Docker containers on OS X. Inside of the xhyve hypervisor,the Docker Engine is running in a tiny small Linux VM, which is based upon theAlpine Linux distribution. With this great combinationof outstanding technologies we as users get the feeling to run Docker containersnatively on our Mac.
Honestly, there are even more great technical details packed into the new “Docker for Mac”release, but we’ll keep them for a later more advanced technical blog post.
There is another big ARM surprise
With the public announcement of “Docker for Mac”, I received an Easter Egg tweet from oneof the Docker engineers, Anil Madhavapeddy, that they’ve just included another coolfeature, which attracts me most. He promised I could even run the Docker images, whichI built for an IoT device like a Raspberry Pi on my Mac now!
No way, that sounds to good to be true. And mainly because the Raspberry Pi usesan ARM CPU, which cannot be executed on an Intel-based Mac, right?
To test this, I’ll select one of my most famous Docker containers:the webserver I’ve presented at DockerCon 2015 San Francisco, CA, last year in June (more details can be found in a dedicated blog post about the Hypriot-Demo and challenge at DockerCon 2015).
Ok, here we go. Let’s run an ARM container on a Mac:
As you can see, it doesn’t work that way…
…hmmm, but maybe with some more magic Docker spells it could be done.
…hmmm, but maybe with some more magic Docker spells it could be done.
And this is where all the magic happens. We’re just bind-mounting a special binaryinto our original ARM-based container. Again, we don’t change the original Dockerimage to get this done. In the end we are really able to run an ARM container,which was built on a Raspberry Pi, now on an Intel-based Mac - just with the helpof some fantastic Docker fuembedded in “Docker for Mac”.
As a last proof, we check with
docker ps
that we’re running the original ARM container from June 2015:This is possible because the Docker engineers have already included the Linux kernel supportfor
binfmt_misc
into “Docker for Mac”. And as long as there is the right Qemu interpreterqemu-arm-static
(which is an Intel binary itself) placed in the ARM container,this container can be executed, or better emulated, even on a foreign CPU architecture.Now I can clearly imagine to use “Docker for Mac” as part of a new Docker-centric workflowto build IoT containers directly on my Mac. Development and testing can be done fast andefficiently on the developers machine and then deploying and running the IoT containerson the target device. A few months ago such an idea has sound pretty crazy and unbelievable -but now it’s coming true soon.
Special thanks to Anil, Justin and all the other great guys at the Docker engineeringteam to make this magic true.
Key Takeaways
After this first and fast walk-through, I guess you’re even more curious and you’dlike to use “Docker for Mac” by yourself. So in the meantime I’ll just summarize thekey points what impressed me most about this great new release.
- installing “Docker for Mac” was pretty easy and slick
- a single
.dmg
media with 90 MByte only - “Docker for Mac” is a real native OS X application
- there are absolutely no other external resources or dependencies to install
- “Docker for Mac” integrates perfectly into your development workflow
- downloading, installing and running the first Docker container takes a few minutes only
- for tiny containers, Alpine Linux is one of the best Linux distros
- ARM IoT containers can be developed and run even on a Mac
- …much more will be revealed in later blog posts
Please send us your feedback on our Gitter channel or tweet your thoughts and ideas on this project at @HypriotTweets.
Dieter @Quintus23M
Please enable JavaScript to view the comments powered by Disqus.comments powered by DisqusIn the previous article, we learned about how to get started with Docker on Linux, macOS, and Windows. In this article, we will get a basic understanding of creating Docker images. There are prebuilt images available on DockerHub that you can use for your own project, and you can publish your own image there.
We are going to use prebuilt images to get the base Linux subsystem, as it’s a lot of work to build one from scratch. You can get Alpine (the official distro used by Docker Editions), Ubuntu, BusyBox, or scratch. In this example, I will use Ubuntu.
Before we start building our images, let’s “containerize” them! By this I just mean creating directories for all of your Docker images so that you can maintain different projects and stages isolated from each other.
![Docker Image For Mac Bash Docker Image For Mac Bash](/uploads/1/2/5/7/125790462/933949798.png)
Now create a Dockerfile inside the dockerprojects directory using your favorite text editor; I prefer nano, which is also easy for new users.
And add this line:
Save it with Ctrl+Exit then Y.
Now create your new image and provide it with a name (run these commands within the same directory):
(Note the dot at the end of the command.) This should build successfully, so you’ll see:
It’s time to run and test your image:
You should see root prompt:
This means you are literally running bare minimal Ubuntu inside Linux, Windows, or macOS. You can run all native Ubuntu commands and CLI utilities.
Let’s check all the Docker images you have in your directory:
You can see all three images: dockp, Ubuntu, andhello-world, which I created a few weeks ago when working on the previous articles of this series. Building a whole LAMP stack can be challenging, so we are going create a simple Apache server image with Dockerfile.
Dockerfile is basically a set of instructions to install all the needed packages, configure, and copy files. In this case, it’s Apache and Nginx.
You may also want to create an account on DockerHub and log into your account before building images, in case you are pulling something from DockerHub. To log into DockerHub from the command line, just run:
Enter your username and password and you are logged in.
Next, create a directory for Apache inside the dockerproject:
Create a Dockerfile inside Apache folder:
And paste these lines:
Then, build the image:
(Note the dot after a space at the end.)
It will take some time, then you should see successful build like this:
Now let’s run the server:
Eureka. Your container image is running. Check all the running containers:
You can kill the container with the docker killcommand:
So, you see the “image” itself is persistent that stays in your directory, but the container runs and goes away. Now you can create as many images as you want and spin and nuke as many containers as you need from those images.
That’s how to create an image and run containers.
To learn more, you can open your web browser and check out the documentation about how to build more complicated Docker images like the whole LAMP stack. Here is aDockerfile file for you to play with. In the next article, I’ll show how to push images to DockerHub.
Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.