How to Deploy Docker Containers with OpenStack Heat

So you have implemented an OpenStack infrastructure. You have also heard about Docker and are aware of the immense amount of buzz it has generated. Well, OpenStack and Docker are two complementary technologies that streamline the operations of teams working in the customary data centers. Docker is an open-source program used to automatically arrange applications into containers. It commoditizes the LXC (Linux Containers) solution and permits users to run numerous containers on one server. On the other hand, OpenStack provides an open API focused on networking, storage, computer, and other services. It simplifies the consumptions of infrastructure to facilitate Container runtimes and Operating systems (you can read more about it in our guide on Container hosting)

One way of enhancing OpenStack is the use of Docker plugins. Docker can easily be integrated into OpenStack Nova as a hypervisor. But, one of the best techniques to combine OpenStack with Docker is to orchestrate its containers with OpenStack Heat.

If you are curious about integrating these technologies, then you have landed on the right page. The manual will help you learn how to integrate Docker into OpenStack. Besides, it will give you an in-depth guide on how to flawlessly install Docker containers with OpenStack Heat. The orchestration is described in details with easy to follow, step by step instructions to make it suitable for all including the beginners.

Ready? Let’s roll!

Special Note: before deploying Docker containers using OpenStackHeat you will require a Linux virtual server. Consult with Hostadvice to find the best Linux hosting providers, complete with real user reviews.

Part One:
Install Docker Plugin

Step one: Download the plugin

The Docker plugin is contained in the Heat folder (zip folder) that is available on GitHub via:

Download the folder and unzip it using:


Once you unzip the folder, locate the tests folder and remove it to avoid conflicts:

cd heat-stable-icehouse/contrib/
rm -rf docker/docker/tests

Step 2: Create a directory

Next, use the command below to fashion a new directory under the folder /usr/lib/heat/:

cp -r docker/* /usr/lib/heat/docker-plugin

Step 3: Install the plugin

Now, the stage is set for the installation of the Docker plugin. Run the following command to initiate the task.

cd /usr/lib/heat/docker-plugin
apt-get install python-pip
pip install -r requirements.txt

The /etc/heat/heat.conf file must be edited before the service is restarted. Use the command below to edit this file:

vi /etc/heat/heat.conf

You can now restart services using the command:

service heat-api restart
service heat-api-cfn restart
service heat-engine restart

Part Two:
Create The Heat Template

In this guide, we’ll dockerize and deploy a LAMP application. For this reason, we must create two Docker containers; one that runs on MySQL database and another that runs on Apache with PHP.
We outline an OS::Heat::SoftwareConfig resource that defines the configuration and another one OS::Heat::SoftwareDeployement resource to deploy configs on the docker server. Then we can link a floating IP to OS::Nova::server to enable it to connect to the internet.  We’ll also create two Docker containers taking the form DockerInc::Docker::Container on our Docker host.

: We are only creating a simple Heat template for the sake of this guide. A more enhanced template can be created using multiple parameters such as names, links, bindings, ports, and more. The enhanced Heat template facilitates the multifaceted use of Docker. However, the Docker plugin we are using doesn’t support these parameters.

Create the template

Create a template in the folder docker-stack.yml and add the following content;

$ vi docker-stack.yml

heat_template_version: 2013-05-23

description: >
  Dockerize a multi-node application with OpenStack Heat.
  This template defines two docker containers running
  apache with php and mysql database.

    type: string
    description: >
      Name of a KeyPair to enable SSH access to the instance. Note that the
      default user is ec2-user.
    default: key1

    type: string
    description: Instance type for the docker server.
    default: m1.medium

    type: string
    description: >
      Name or ID of the image to use for the Docker server.  This needs to be
      built with os-collect-config tools from a Fedora base image.
    default: fedora-software-config

    type: string
    description: name of public network for which floating IP addresses will be allocated.
    default: nova

    type: OS::Heat::SoftwareConfig
      group: script
      config: |
        #!/bin/bash -v
        setenforce 0
        yum -y install docker-io
        cp /usr/lib/systemd/system/docker.service /etc/systemd/system/
        sed -i -e '/ExecStart/ { s,fd://,tcp://, }' /etc/systemd/system/docker.service
        systemctl start docker.service
        docker -H :2375 pull marouen/mysql
        docker -H :2375 pull marouen/apache

    type: OS::Heat::SoftwareDeployment
      config: {get_resource: configuration}
      server: {get_resource: docker_server}

    type: OS::Nova::Server
      key_name: {get_param: key}
      image: { get_param: image }
      flavor: { get_param: flavor}
      user_data_format: SOFTWARE_CONFIG

    type: OS::Nova::FloatingIP
      pool: { get_param: public_net}

    type: OS::Nova::FloatingIPAssociation
      floating_ip: { get_resource: server_floating_ip}
      server_id: { get_resource: docker_server}

    type: DockerInc::Docker::Container
    depends_on: [deployment]
      image: marouen/mysql
        - 3306
          template: http://host:2375
            host: {get_attr: [docker_server, networks, private, 0]}

    type: DockerInc::Docker::Container
    depends_on: [mysql]
      image: marouen/apache
        - 80
          template: http://host:2375
            host: {get_attr: [docker_server, networks, private, 0]}

    description: Public address of apache
        template: http://host
          host: {get_attr: [docker_server, networks, private, 0]}

Part Three:
Deploy The Stack

Once, you create the template you can proceed with the deployment of your stack.

Step 1: Create a credential file

Before you deploy the stack you should create a credential file using the following command:

vi creds

#Paste the following:
export OS_TENANT_NAME=admin
export OS_TENANT_NAME=admin
export OS_PASSWORD=admin_pass
export OS_AUTH_URL="http://controller:5000/v2.0/"

Follow the steps below to create fedora-based image

$ git clone
git clone
git clone
git clone
export PATH="${PWD}/dib-utils/bin:$PATH"
export ELEMENTS_PATH=tripleo-image-elements/elements:heat-templates/hot/software-config/elements
diskimage-builder/bin/disk-image-create vm \
  fedora selinux-permissive \
  os-collect-config \
  os-refresh-config \
  os-apply-config \
  heat-config-ansible \
  heat-config-cfn-init \
  heat-config-docker \
  heat-config-puppet \
  heat-config-salt \
  heat-config-script \
  -o fedora-software-config.qcow2
glance image-create --disk-format qcow2 --container-format bare --name fedora-software-config < \
  fedora-software-config.qcow2 $

If you are yet to create a key, run the following command:

nova keypair-add --pub-key ~/.ssh/ key1

To enable access to your Docker server, we incorporate rules to our default security group:

$ Permit ICMP (ping):

nova secgroup-add-rule default icmp -1 -1

$ Permit secure shell (SSH) access:

nova secgroup-add-rule default tcp 22 22

$ Permit 2375 port access (Docker endpoint):

nova secgroup-add-rule default tcp 2375 2375

Then use the following command to produce a private network:

source creds

$Create a private network:

nova network-create private --bridge br100 --multi-host T  --dns1  \
--gateway --fixed-range-v4

Next, create the floating IP pool:

nova-manage floating create --pool=nova --ip_range=

Step 2: Create your stack

Now, we’ll create our stack from the newly created template.

source creds

heat stack-create -f docker-stack.yml docker-stack

Next, verify that your stack was successfully created:

heat stack-list

The window below will appear after stack launching:

Run the following command to confirm that your containers are successfully created:

ssh ec2-user@

sudo docker -H :2375 ps

You will get the following output:

That’s it! You have successful installed Docker containers with OpenStack Heat.

Check out the top 3 Linux hosting services

Was this article helpful?