Jump to: navigation, search


Revision as of 15:38, 21 July 2014 by Ewindisch (talk | contribs) (Update for changes in driver, plus minor edits)


The Docker driver is a hypervisor driver for Openstack Nova Compute. It was introduced with the Havana release, but lives out-of-tree for Icehouse and Juno. Being out-of-tree has allowed the driver to reach maturity and feature-parity faster than would be possible should it have remained in-tree. It is expected the driver will return to mainline Nova in the Kilo release.

Docker is an open-source engine which automates the deployment of applications as highly portable, self-sufficient containers which are independent of hardware, language, framework, packaging system and hosting provider.

Docker provides management of Linux containers with a high level API providing a lightweight solution that runs processes in isolation. It provides a way to automate software deployment in a secure and repeatable environment. A Docker container includes a software component along with all of its dependencies - binaries, libraries, configuration files, scripts, virtualenvs, jars, gems, tarballs, etc. Docker can be run on any x64 Linux kernel supporting cgroups and aufs.

Docker is a way of managing multiple containers on a single machine. However used behind Nova makes it much more powerful since it’s then possible to manage several hosts, which in turn manage hundreds of containers. The current Docker project aims for full OpenStack compatibility.

Containers don't aim to be a replacement for VMs, they are complementary in the sense that they are better for specific use cases.

What unique advantages Docker bring over other containers technologies?

Docker takes advantage of containers and filesystem technologies in a high-level which are not generic enough to be managed by libvirt.

  • Process-level API: Docker can collect the standard outputs and inputs of the process running in each container for logging or direct interaction, it allows blocking on a container until it exits, setting its environment, and other process-oriented primitives which don’t fit well in libvirt’s abstraction.
  • Advanced change control at the filesystem level: Every change made on the filesystem is managed through a set of layers which can be snapshotted, rolled back, diff-ed etc.
  • Image portability: The state of any docker container can be optionally committed as an image and shared through a central image registry. Docker images are designed to be portable across infrastructures, so they are a great building block for hybrid cloud scenarios.
  • Build facility: docker can automate the assembly of a container from an application’s source code. This gives developers an easy way to deploy payloads to an OpenStack cluster as part of their development workflow.

How the Nova hypervisor works under the hood?

The Nova driver embeds a tiny HTTP client which talks with the Docker internal Rest API through a unix socket. It uses the HTTP API to control containers and fetch information about them.

The driver will fetch images from the OpenStack Image Service (Glance) and load them into the Docker filesystem. Images may be placed in Glance by exporting them from Docker using the 'docker save' command.

Older versions of this driver required running a private docker-registry, which would proxy to Glance. This is no longer required.


Configure OpenStack to enable Docker

Installing Docker for OpenStack

First of all, the first requirement is to install Docker.

If you just want to try it quickly, you can just follow the following slides as a tutorial: http://www.slideshare.net/dotCloud/docker-open-stack

If you are co-locating the docker registry alongside the Glance service:

sudo yum -y install docker-registry

and in /etc/sysconfig/docker-registry set the REGISTRY_PORT and SETTINGS_FLAVOR, as follows:

export SETTINGS_FLAVOR=openstack
export REGISTRY_PORT=5042

In that file you will also need to specify the OpenStack authentication variables. If using the RDO installation, the following accomplishes that:

. /root/keystonerc_admin
export OS_GLANCE_URL=http://localhost:9292

By default, /etc/docker-registry.yml sets the (local, alternate) storage_path for the openstack configuration under /tmp. You may want to alter the path to a more permanent location:

   storage: glance
   storage_alternate: local
   storage_path: /var/lib/docker-registry

In order for Nova to communicate with Docker over its local socket, add nova to the docker group and restart the compute service to pick up the change:

usermod -G docker nova
service openstack-nova-compute restart

Start Redis (used by the Docker Registry), if it wasn't already

sudo service redis start
sudo chkconfig redis on

Finally, start the registry:

sudo service docker-registry start
sudo chkconfig docker-registry on

Nova configuration

Nova needs to be configured to use the Docker virt driver.

Edit the configuration file /etc/nova/nova.conf according to the following options:

compute_driver = docker.DockerDriver

Optionally if you want to use your own docker-registry which listens on a port different than 5042, you can override the following option:

docker_registry_default_port = 5042

Glance configuration

Glance needs to be configured to support the "docker" container format. It's important to leave the default ones in order to not break an existing glance install.

container_formats = ami,ari,aki,bare,ovf,docker

Deployment with DevStack

Using Docker hypervisor through DevStack replaces all manual configuration needed above.

Before running DevStack's stack.sh script, configure the following options in the "localrc" file:


Then, run Docker install script from the devstack directory:

NOTE: socat is needed for the script (usually installed by stack.sh). If you don't have socat installed, run "apt-get install socat"

$ ./tools/docker/install_docker.sh

Finally, run stack.sh from devstack directory:

$ ./stack.sh

How to use it

Once you configured Nova to use the docker driver, the flow is the same as any other driver.

$ glance image-list
| ID                            | Name                            | Disk Format | Container Format | Size     | Status |
| f5049d8b-93cf-49ab-af56-e7... | cirros-0.3.1-x86_64-uec         | ami         | ami              | 25165824 | active |
| 0f1ec86c-157f-4f22-9889-c0... | cirros-0.3.1-x86_64-uec-kernel  | aki         | aki              | 4955792  | active |
| 03a54807-2e35-4864-a337-45... | cirros-0.3.1-x86_64-uec-ramdisk | ari         | ari              | 3714968  | active |
| 77083f3c-d320-46e3-bcba-0c... | docker-busybox:latest           | raw         | docker           | 2271596  | active |

Only images with a "docker" container format will be bootable. The image contains basically a tarball of the container filesystem.

NOTE: Docker supports inheritance between images, so it's possible to have several "docker" images without a name (None). It's usually an image dependence. These images are bootable as well, the filesystem will basically have a previous state. But it's probably not what you want to use in the first place.

It's recommended to add new images to Glance by using Docker. For instance, here is how you can fetch images from the public registry and push them back to Glance in order to boot a Nova instance with it:

 $ docker search hipache
Found 3 results matching your query ("hipache")
NAME                             DESCRIPTION
samalba/hipache                  https://github.com/dotcloud/hipache

Then, tag the image with the docker-registry location and push it.

 $ docker pull samalba/hipache
 $ docker tag samalba/hipache
 $ docker push
The push refers to a repository [] (len: 1)
Sending image list
Pushing repository (1 tags)
Push 100% complete

Note that "" is the IP address of my host, it would definitely work with "localhost" since my docker-registry is inside a container (however the port is important).

In this case, the docker-registry (running in a docker container with a port mapped on 5042) will push the images to Glance. From there Nova can reach them and you can verify it with the glance cli.

 $ glance image-list
| ID                            | Name                            | Disk Format | Container Format | Size     | Status |
| f5049d8b-93cf-49ab-af56-e7... | cirros-0.3.1-x86_64-uec         | ami         | ami              | 25165824 | active |
| 0f1ec86c-157f-4f22-9889-c0... | cirros-0.3.1-x86_64-uec-kernel  | aki         | aki              | 4955792  | active |
| 03a54807-2e35-4864-a337-45... | cirros-0.3.1-x86_64-uec-ramdisk | ari         | ari              | 3714968  | active |
| 77083f3c-d320-46e3-bcba-0c... | docker-busybox:latest           | raw         | docker           | 2271596  | active |
| 998f52ba-fe03-46b0-b5a6-4b... | hipache:latest                  | raw         | docker           | 486      | active |

You can obviously boot instances from nova cli:

 $ nova boot --image "docker-busybox:latest" --flavor m1.tiny test
| Property                             | Value                                |
| OS-EXT-STS:task_state                | scheduling                           |
| image                                | docker-busybox:latest                |
| OS-EXT-STS:vm_state                  | building                             |
| OS-EXT-SRV-ATTR:instance_name        | instance-0000002d                    |
| OS-SRV-USG:launched_at               | None                                 |
| flavor                               | m1.micro                             |
| id                                   | 31086c50-f937-4f80-9790-045096ecb32c |
| security_groups                      | [{u'name': u'default'}]              |
| user_id                              | 1a3eed38d1344e869dd019b3636db12b     |
| OS-DCF:diskConfig                    | MANUAL                               |
| accessIPv4                           |                                      |
| accessIPv6                           |                                      |
| progress                             | 0                                    |
| OS-EXT-STS:power_state               | 0                                    |
| OS-EXT-AZ:availability_zone          | nova                                 |
| config_drive                         |                                      |
| status                               | BUILD                                |
| updated                              | 2013-08-25T00:22:32Z                 |
| hostId                               |                                      |
| OS-EXT-SRV-ATTR:host                 | None                                 |
| OS-SRV-USG:terminated_at             | None                                 |
| key_name                             | None                                 |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | None                                 |
| name                                 | test                                 |
| adminPass                            | QwczSPAAT6Mm                         |
| tenant_id                            | 183a9b7ed7c6465f97387458d693ca4c     |
| created                              | 2013-08-25T00:22:31Z                 |
| os-extended-volumes:volumes_attached | []                                   |
| metadata                             | {}                                   |

Once the instance is booted:

$ nova list
| ID                                   | Name | Status | Task State | Power State | Networks         |
| 31086c50-f937-4f80-9790-045096ecb32c | test | ACTIVE | None       | Running     | private= |

You can also see the corresponding container on docker:

$ docker ps
docker ps
ID              IMAGE                                  COMMAND      CREATED             STATUS          PORTS
f337c7fec5ff   sh           10 seconds ago      Up 10 seconds

The command used here is the one configured in the image. Each container image can have a command configured for the run. The driver does not override this. You can image booting an apache2 instance, it will start the apache process if the image is authored properly via a Dockerfile.