Displaying Docker images on Openstack

Displaying Docker images on Openstack

Let’s look at a basic procedure about using Docker and its interaction with a private cloud Openstack; Several concepts of this input will be useful to deploy solutions of this type as we will see how to connect to an Amazon AWS cloud using keys, altering Docker images, using the Docker Hub, connecting to a Droplet of Digital Ocean and creating a cloud Openstack Using DevStack.

Instance Settings

To begin, let’s configure our connection to AWS to create an instance of Ubuntu 14.04 in order to install Docker and modify a basic image. Once the image is provisioned, we do sudo apt–get update & sudo apt–get–y upgrade to update the operating system. Here our instance.

The PuTTY connection was configured as follows, the AWS-Uniqs-Ubuntu.ppk file was generated with PuTTYGen from the key provided by AWS; for the case of Ubuntu servers, the Host Name must be specified in the format “ubuntu @ <Public DNS>”. This reference will help us generate the .ppk file (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html?icmpid=docs_ec2_console)

Install docker

Once the instance is available we proceed to install Docker. We first ensure that aufs is available:

Sudo apt-get install linux-image-extra-`uname -r 

We add the docker repository

Sudo apt-key adv --keyserver hkp: //pgp.mit.edu: 80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | Sudo tee /etc/apt/sources.list.d/docker.list
Sudo apt-get update

We download and install docker

Sudo apt-get install docker-engine

Docker Application

Let’s use Webapp, which is a pre-built image that contains a simple Python web application and whose purpose is to be able to instantiate a small Python code; our goal is to show you how to manipulate it on a standalone server and then “plug in” that image into a private Openstack cloud (even using another public cloud provider).

We execute docker run to raise a container with the following parameters.

$ sudo docker run -P -t -i training/webapp /bin/bash

  • P: Instructs docker to map the required ports within the range of those exposed.
  •  t: Allocate a pseudo-TTY
  •  i: Interactive
  •  training / webapp. We will use the webapp image.
  • / bin / bash. It will allow us to run an interactive Shell inside the container.

This container gives us a simple application whose output is the following.

In another ssh session we execute the command “docker ps –a”, that allows us to know the state of the container (Up, Down, etc.), its name, involved ports.

$ sudo docker ps -a
84c66094c852 training/webapp "/bin/bash" 11 seconds ago Up 10 seconds>5000/tcp angry_mclean

In our case, the web application offered by the Python code runs on port 32768. Let’s do a basic connectivity review with telnet to see if my app actually listens on the port informed.

$ telnet 32768
Connected to
Escape character is '^]'.

Let’s go back to the interactive container shell to edit the app.py file to alter its content

$ sudo docker run -P -t -i training/webapp /bin/bash 
root@7d8a7cbebee5:/opt/webapp# vi app.py

File app.py

import os
from flask import Flask
app = Flask(__name__)
def hello():
 provider = str(os.environ.get('PROVIDER', 'world'))
 return 'Hello '+provider+'!'
if __name__ == '__main__':
 # Bind to PORT if defined, otherwise default to 5000.
 port = int(os.environ.get('PORT', 5000)) app.run(host='', port=port)

We will change

"provider = str(os.environ.get('PROVIDER', 'world'))" por "provider = str(os.environ.get('PROVIDER', 'guys'))"

We will save a new image on the same server but in this case with the new Python code, we raise a new container to verify that everything works in a satisfactory way and then we will upload it to the Docker Hub.

$ sudo docker commit -a "Pablo" -m "GuysxWorld" 84c66094c852 pablocalvo/webapp:1.0

• -m: Useful for version control.
• -a: It allows us to specify an author for our update.

$ sudo docker run -P pablocalvo/webapp:1.0 python app.py
* Running on (Press CTRL+C to quit)

We enter our Hub and execute the Push to upload the image.

$ sudo docker login -u pablocalvo
Login Succeeded
$ sudo docker push pablocalvo/webapp:1.0
The push refers to a repository [docker.io/pablocalvo/webapp]
be5d1b73e5eb: Pushed
1154ba695078: Pushed
1.0: digest: sha256:986e81d8f82405fe88d20e138ce696c1fecbba156ddc33fdb0c08654faad0507 size: 8819

We have successfully uploaded our image to the Hub.

Configuring Openstack

Now we are going to hire a Droplet in Digital Ocean to install and configure Openstack on a single server, in our case Ubuntu; the server must have at least 4 Gb of RAM.

The installation guide is available here: http://docs.openstack.org/developer/devstack/guides/single-machine.html, we will basically run the devstack script, which is very useful for achieving an openstack base configuration based on Screens.

We create the user “stack”

adduser stack

We install sudo, we configure the user “stack” so that it does not require a key when executing sudo.

apt-get install sudo -y || yum install -y sudo
echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

We install git and download the Devstack repository.

sudo apt-get install git -y || sudo yum install -y git
git clone https://git.openstack.org/openstack-dev/devstack
cd devstack

Before launching DevStack we have configured the /home/stack/devstack/local.conf file as follows.


ADMIN_PASSWORD=<some password> 
DATABASE_PASSWORD=<some password> 
RABBIT_PASSWORD=<some password> 
SERVICE_PASSWORD=<some password>

Next, the execution of the command and its completion
$ ./stack.sh 
This is your host IP address: 
This is your host IPv6 address: ::1 
Horizon is now available at 
Keystone is serving at 
The default users are: admin and demo 
The password: <same password>

Once we have configured our Openstack cloud, we must adapt it to accept Docker images (https://wiki.openstack.org/wiki/Docker) and we must install docker on the server (See “Installing Docker” in this blog)

Nova configuration

Nova must be configured to be able to use the docker driver; For this you must configure the file /etc/nova/nova.conf as follows:

[DEFAULT] compute_driver = novadocker.virt.docker.DockerDriver 

Nova must be configured to be able to use the docker driver; To do this, you must configure the /etc/nova/nova.conf file as follows:

Compute_driver = novadocker.virt.docker.DockerDriver

We must create the /etc/nova/rootwrap.d directory if it does not exist and write the file “docker.filters” as follows:

Ln: CommandFilter, / bin / ln, root

Configuration of glance

[DEFAULT] container_formats = ami,ari,aki,bare,ovf,docker

Once we have made the case configurations, we proceed to create a local copy of the image hosted in the Hub.

$ docker pull pablocalvo/webapp:1.0 
1.0: Pulling from pablocalvo/webapp 
e190868d63f8: Pull complete 
349abde8a623: Pull complete 
Digest: sha256:986e81d8f82405fe88d20e138ce696c1fecbba156ddc33fdb0c08654faad0507 
Status: Downloaded newer image for pablocalvo/webapp:1.0 

Now let’s incorporate the image into the openstack cloud

$ docker save pablocalvo/webapp:1.0 | glance image-create --container-format=docker --disk-format=raw --name=pablocalvo-webapp
  • Image-greate: Instructs glance to create an image
  • Container-format: Determines that the container to be created from the image will be docker type.
  • Disk-format: The format of the image; Can be ami, ari, aki, vhd, vmdk, raw, qcow2, vdi and iso.
  • Name: is the name of the image

Let’s verify that it is effectively under the control of Glance

$ glance image-list 
| ID | Name | +--------------------------------------+---------------------------------+ 
| 9ba9989b-1c38-4875-ba33-fdd593edc818 | cirros-0.3.4-x86_64-uec | 
| ddfca0dc-0236-4a62-bdaf-3061bf96cd27 | cirros-0.3.4-x86_64-uec-kernel | 
| ef5a5fcb-4eb6-490c-912c-ede1f07bfbbd | cirros-0.3.4-x86_64-uec-ramdisk | 
| b7d3c11a-c675-46d3-bef4-f70b0edb3492 | pablocalvo-webapp | 
+--------------------------------------+---------------------------------+ $ docker save pablocalvo/webapp:1.0 | glance image-create --container-format=docker --disk-format=raw --name=pablocalvo-webapp

And that it is a Docker image

Now, we only have to create an instance using the previously loaded image

In this post we have developed a sequential procedure of deploying a docker image on an Openstack cloud in order to understand the potential of using container technology in conjunction with cloud computing services. This guide will allow you to apply to practical cases, from “dockerized” applications that can be “plugged in” to productive Openstack installations.

By Uniqs.

Dejá un comentario

Tu dirección de correo electrónico no será publicada. Los campos necesarios están marcados *