|
|
Log in / Subscribe / Register

Deploying Docker

By Nathan Willis
October 16, 2013

The Docker project is not (like its name might suggest) yet another desktop application launcher. Rather, it is an application deployment system designed to make it easy for programmers to develop an application on one type of machine (such as a work laptop) and package it for predictable usage on a variety of other machines (such as a cloud instance or server farm). A Docker package is a container that can be deployed and run in nearly any Linux environment, but it is not a virtual machine image—instead, it is a self-contained copy-on-write duplicate of a master application image. It comes with some awkward technical baggage, but the ideas behind Docker proved compelling enough that one Red Hat developer recently took it upon himself to figure out how to adapt the system for standard Linux distributions.

The Docker site compares its deployment model with the idea of the standard shipping container: just as standard containers allow freight companies to move cargo on any vessel without modifying either the vessel or the payload, a Docker package is designed to be self-sufficient. It can be packaged up anywhere, then unpacked and installed anywhere. Each Docker application runs as its own LXC process container, with full network and resource isolation from the others. Cgroups and namespaces must also be enabled, although Docker will run with some cgroups (such as the memory controller) disabled.

The same claims would be made about VM deployments, of course. Where Docker differs is that it only containerizes the application and its dependencies; the process container runs directly on the host OS. This makes for smaller packages, less overhead, and faster application restarts. Multiple copies of each Docker container can be deployed together on the same server, sharing libraries. In this scenario, Docker again saves space by storing the containers on a union file system (specifically, AnotherUnionFS or AUFS). Only the differences between the various copies of the application need to be saved, so read-only portions of each application take up zero additional space.

Because each Docker container is a copy of the same original, starting up an additional instance of the application is also far faster than spinning up another VM. The AUFS filesystem can also be exploited when rolling out application updates, overwriting only the changed portions of the application.

Docker development is sponsored by dotCloud, a platform-as-a-service vendor. The system undoubtedly makes for a good base on which to build a cloud service, since the marginal savings over a VM approach continue to scale up as more and more applications are deployed. Nevertheless, it has attracted attention from cloudless developers as well, who would like to see it available on general-purpose machines running Red Hat Enterprise Linux (RHEL), Ubuntu, and other large distributions. On those systems, the cloud-scalability advantages might not be a significant factor, but the other ease-of-deployment features could still prove helpful.

The problem is that Docker relies on AUFS for so much of its functionality. AUFS is not part of the mainline Linux kernel; it is a patch set. Furthermore, the only major distribution to build AUFS support in the kernels it ships is Ubuntu—and Ubuntu has announced plans to deprecate it in favor of an upstream replacement.

That problem evidently got Red Hat's Alex Larsson thinking. Larsson wrote a blog post on October 15 describing his recent effort to get Docker working on top of a different filesystem. The obvious solution might be to use overlayfs, which seems to be on track for landing in the upstream kernel, but Larsson felt that it was not yet ready for use. Similarly, Btrfs has copy-on-write functionality, but Btrfs is not yet stable enough for many users.

Eventually, Larsson decided to try porting Docker to use Logical Volume Manager (LVM) thin provisioning with a little trickery from the kernel device-mapper: he creates a copy-on-write block device pool with LVM thin provisioning, then creates an ext4 "base" device on top of it. Each Docker container is then created as an LVM snapshot of that base device. The LVM thin provisioning means that the copy-on-write device only takes up space for the actual files it uses; since the LVM snapshots are layered on top of the base image, they automatically reuse the files below.

Larsson reports that there are still some issues to work out (such as how to overcome the various maximum sizes on the filesystems used), but he hopes to have the work land in time for the upcoming Docker 0.7 release. That may not make Docker ready for deployment on vanilla RHEL machines any time soon, but it is a step in the right direction. Larsson said he thinks the long-term solution will probably be to port Docker over to overlayfs, but in the meantime, the LVM-based approach looks like a good—and clever—workaround.


to post comments

Deploying Docker

Posted Oct 17, 2013 0:55 UTC (Thu) by idupree (guest, #71169) [Link]

It is device-mapper based; it is not actually using LVM. One won't need to be using LVM to use Docker.

The relation: LVM also uses device-mapper. Docker's upcoming device-mapper usage is modeled after LVM thin provisioning. Larsson's blog post explained it pretty well, I think.

Debian also has aufs

Posted Oct 17, 2013 9:37 UTC (Thu) by juliank (guest, #45896) [Link] (5 responses)

Not only Ubuntu

Debian also has aufs

Posted Oct 17, 2013 16:16 UTC (Thu) by dpquigl (guest, #52852) [Link] (4 responses)

I also don't agree with Ubuntu's assessment that it will never be merged upstream. I agree that AUFS is complex. Even though AUFS is a complete rewrite at this point of our original UnionFS implementation it suffers from the same problems that all stackable file systems do. That the kernel is not really made to support file system stacking and as such there are a lot of issues with data structures potentially changing from underneath us. Even with this concern I found a mailing list post on LKML where Al Viro said he was open to looking at these implementations again for inclusion. In the past he had said no way no how for implementations like AUFS but with that latest statement there might be hope to get it upstreamed.

Stackable file systems in general are a bit complex since you're rebuilding part of the VFS and are essentially building in support for the equivalent of a windows filter driver at the file system level. That complexity shouldn't preclude it from inclusion though as long as its clean and properly documented (which we have documentation for stackable file systems in the Documentation folder).

Debian also has aufs

Posted Oct 17, 2013 17:01 UTC (Thu) by alexl (guest, #19068) [Link] (1 responses)

The one viro is looking on for possible inclusion is overlayfs, not aufs.

Debian also has aufs

Posted Oct 17, 2013 20:45 UTC (Thu) by dpquigl (guest, #52852) [Link]

Based on the email I read it seems like he would give consideration to any union namespace implementation. I would like to see a feature comparison though. Last I checked Unionfs/AUFS/overlayfs/unionmounts did not all provide the same functionality and I think that some of the features of AUFS might be needed for Docker.

"I *have* looked at unionmount lately, and the recent modifications dhowells
is doing there are closing most of my problems with that; on the other hand,
there's no fundamental reason why both can't get merged. Hell, might as
well resurrect aufs, while we are at it..." - Al Viro

https://lkml.org/lkml/2013/3/12/637

Debian also has aufs

Posted Oct 17, 2013 18:22 UTC (Thu) by juliank (guest, #45896) [Link]

IIRC, he made a joke about including aufs.

Debian also has aufs

Posted Oct 17, 2013 21:09 UTC (Thu) by dpquigl (guest, #52852) [Link]

Also a minor nit for the article. It says the only differences between files are saved. This is not correct. Only the modified files are saved would be more correct. AUFS OverlayFS and unionmounts are namespace unification file systems. They just unify the name space not the data in the files itself. So a 1 byte change to a 400 meg file will cause the 400 meg file to be copied up to the r/w branch.

Deploying Docker

Posted Oct 17, 2013 9:37 UTC (Thu) by alexl (guest, #19068) [Link]

Re: "such as how to overcome the various maximum sizes on the filesystems used"

Its not that there is a maximum size for a particular filesystem type, but rather that to use a block device we have to make the base filesystem some particular size, and once some container needs more space we need to be able to resize that filesystem instance.

Deploying Docker

Posted Nov 27, 2013 8:36 UTC (Wed) by jospoortvliet (guest, #33164) [Link] (2 responses)

I wonder what is unstable about btrfs for this purpose? Does it need btrfs functionality not yet stable, like de-duplication?

Deploying Docker

Posted Nov 27, 2013 13:49 UTC (Wed) by rleigh (guest, #14622) [Link] (1 responses)

I have been doing this with schroot's "btrfs-snapshot" chroot type for a few years now without running into a single problem relating to snapshotting/subvolumes. Not that btrfs is stable enough for me to trust for anything but transient snapshots, but that's ideal for this type of usage, and btrfs snapshots are super fast and you can create dozens of snapshots in parallel for e.g. parallel build jobs. I've found them to be more robust than LVM snapshots in practice; rapid parallel snapshotting of LVM LVs will rapidly lock up the kernel (unless it's been fixed in the interim--I just stopped pushing it so hard).

The only Btrfs limitation I've found is the lack of being able to atomically replace one subvolume with another (e.g. if you want to replace the original subvolume with an updated snapshot atomically). In practice you have to do two renames, so it's not atomic.

Deploying Docker

Posted Nov 27, 2013 15:55 UTC (Wed) by mathstuf (subscriber, #69389) [Link]

> In practice you have to do two renames, so it's not atomic.

Has there been thought of a swap() syscall (and probably a corresponding coreutils program) to do this? I want this for normal files as well often enough…


Copyright © 2013, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds