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:
https://github.com/openstack/heat/tree/stable/icehouse
Download the folder and unzip it using:
unzip heat-stable-icehouse.zip
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 (add) plugin_dirs=/usr/lib/heat/docker-plugin/docker
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: 2024-05-23 description: > Dockerize a multi-node application with OpenStack Heat. This template defines two docker containers running apache with php and mysql database. parameters: key: type: string description: > Name of a KeyPair to enable SSH access to the instance. Note that the default user is ec2-user. default: key1 flavor: type: string description: Instance type for the docker server. default: m1.medium image: 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 public_net: type: string description: name of public network for which floating IP addresses will be allocated. default: nova resources: configuration: type: OS::Heat::SoftwareConfig properties: 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://0.0.0.0:2375, }' /etc/systemd/system/docker.service systemctl start docker.service docker -H :2375 pull marouen/mysql docker -H :2375 pull marouen/apache deployment: type: OS::Heat::SoftwareDeployment properties: config: {get_resource: configuration} server: {get_resource: docker_server} docker_server: type: OS::Nova::Server properties: key_name: {get_param: key} image: { get_param: image } flavor: { get_param: flavor} user_data_format: SOFTWARE_CONFIG server_floating_ip: type: OS::Nova::FloatingIP properties: pool: { get_param: public_net} associate_floating_ip: type: OS::Nova::FloatingIPAssociation properties: floating_ip: { get_resource: server_floating_ip} server_id: { get_resource: docker_server} mysql: type: DockerInc::Docker::Container depends_on: [deployment] properties: image: marouen/mysql port_specs: - 3306 docker_endpoint: str_replace: template: http://host:2375 params: host: {get_attr: [docker_server, networks, private, 0]} apache: type: DockerInc::Docker::Container depends_on: [mysql] properties: image: marouen/apache port_specs: - 80 docker_endpoint: str_replace: template: http://host:2375 params: host: {get_attr: [docker_server, networks, private, 0]} outputs: url: description: Public address of apache value: str_replace: template: http://host params: 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 https://git.openstack.org/openstack/diskimage-builder.git git clone https://git.openstack.org/openstack/tripleo-image-elements.git git clone https://git.openstack.org/openstack/heat-templates.git git clone https://git.openstack.org/openstack/dib-utils.git 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:
ssh-keygen nova keypair-add --pub-key ~/.ssh/id_rsa.pub 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 0.0.0.0/0
$ Permit secure shell (SSH) access:
nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
$ Permit 2375 port access (Docker endpoint):
nova secgroup-add-rule default tcp 2375 2375 0.0.0.0/0
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 8.8.8.8 --gateway 172.16.0.1 --fixed-range-v4 172.16.0.0/24
Next, create the floating IP pool:
nova-manage floating create --pool=nova --ip_range=192.168.100.100/28
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@192.168.100.97 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
- You can discover new info about Best website hosting by clicking this link.