Sunday, March 30, 2014

Running Docker container in oVirt

Overview

I recently wrote a new UI plugin in oVirt, that allows creating a VM that will run a Docker container inside it. This post shares the information about it, explains how to use it and what are the prerequisites.

What is it good for?

Well, Docker gives a very cool wrapping on top of linux containers. In addition, it also gives a public repository people can use! That makes it very easy to both create and consume container images that give different services, such as application servers, databases and many other services. Using the UI plugin to run that inside oVirt makes the job of deploying an existent service as easy as clicking a button (well... some steps are required first, but not too much steps :-) ).

Setting it up

In order to use the UI plugin you first need to fetch it from the samples-uiplugins git repository. The git repository is in git://gerrit.ovirt.org/samples-uiplugins. The plugin is currently being reviewed, so it is available at Docker-Plugin-Patch. Copy the plugin files to /usr/share/ovirt-engine/ui-plugins, so that you'll have the following directory structure:
  • docker.json
  • docker-resources/
  • docker-resources/plugin.html
  • docker-resources/icon_help.png
  • docker-resources/launch-docker-dialog.html
  • docker-resources/progress.gif

Then, you need to configure it. I usually do that using the docker.json file, although you can create a user-specific file as well. The relevant entries to configure are:
  1. allowedOrigins - that entry is used in order to pass messages between the UI plugin infrastructure and the plugin itself. I'll make it simple and just say you need to put the engine URL there, at the same way you access it with your browser (http://engine-server:port, or https://engine-server:port)
  2. apiEntryPoint - API entry point. Usually something like http(s)://engine-server:port/ovirt-engine/api
  3. dockerImages - Images you wish to be able to run. It can be either just an image name, or something more specific like user/image:label

Using the plugin


How does it work?

  • The UI plugin that allows the user to create a new oVirt VM, that runs a selected docker image running a specified command
  • It uses the cloud-init integration in order to pass the docker commands to the guest
  • docker image is downloaded from the public registry to the VM on first launch

Prerequisites

The plugin is based on creating a new oVirt VM from a template, passing cloud-init arguments that will configure and run the docker container.
Thus, in order to use it you need to have a Fedora image with docker service (with -r option to make containers start also after VM), cloud-init, and ovirt-guest-agent

It works only in cluster level 3.4 and above, as it requires persisting the cloud-init properties

Make sure the template you create have enough storage, as it might be required when downloading docker images. If you're interested in specific images then I recommend to pull them to the VM you create the template from, that way they'll be available, and won't require downloading the image when starting the container.

Plugin in action

1. You first login to the oVirt admin portal, and go the the VM main tab:



2. There you'll see the "Create Docker VM" button.
3. Press on it, and you'll see the following dialog:


4. Fill in the details:
  • Choose a DC
  • Choose a Cluster
  • Choose a Template that follows the prerequisites above
  • Fill in other VM properties
  • Fill in the Docker details (image, port mapping, and command). The command is mandatory only in case the image doesn't have an ENTRYPOINT.
  • Fill in the cloud-init details (I've decided to put only host name and SSH key, for the sake of simplicity).
5. Press OK


The VM is being created now. Once finished you can run it. After a few minutes, the IP address of it will appear in the admin portal, so you can either connect to it via SSH if you want (using the public SSH key you've passed), or just use the service it is supplying. In the screenshot I've created a Jboss instance, so I can just see that browsing results in a Test Page. Here is a screenshot showing the IP address:



And here is the result of browsing to this VM (we have mapped port 80 of the container to port 80 of the VM):


Pre-defined image in glance.ovirt.org

In order to ease the process of using this UI plugin, I've created an image you can import from the public oVirt Glance repository, "CentOS 6.5 64-Bit Docker".
You can import it using the guide available in my previous post (Importing Glance images as oVirt templates). It is based on the CentOS 6.5 cloud image. Make sure to create a virtual NIC in the template after importing, and also to set the relevant OS.

Note that I tested the plugin both using this template, and using a Fedora 19 template, installed from scratch. Using the Fedora 19 cloud image didn't work well for me, as the docker container got stuck on startup.

That's it! Start running containers in oVirt!

28 comments:

  1. Oved - really useful article - bookmarking it! Thanks.

    ReplyDelete
  2. Hi Oved

    Nice article.
    Do you have any idea of the API which can be used to create the drop down box in custom tab?
    i.e instead of "Create docker button" to have drop down menu?

    -Nikita

    ReplyDelete
    Replies
    1. Hi

      I don't think there is such an API call. You can either add a context menu item, or an action button on the top panel.
      However, I suggest you send an E-mail to users@ovirt.org, as the UI plugin maintainer is monitoring this list, so he might suggest an alternative / advise you to open RFE on that.

      Delete
  3. Hi,

    Can we execute any shell commands on the RHEV-M from the ovirt-engine?
    e.g to execute the "ls" command in RHEV_M manager through browser?

    -Nikita

    ReplyDelete
  4. No.
    May I ask what's the need for that?
    In addition, I really recommend to send such questions on users@ovirt.org (which I see that you did, and hopefully your issue will be resolved soon).

    ReplyDelete
  5. Hi,
    I tried using launch-docker-dialog.html script without docker i.e. I tried to update api/vms file but I was not able to do so.
    I tried below code:

    function AttachDevice(apiEntryPoint) {
    var vvmsUrl = apiEntryPoint + "/vms";
    var data1="null";
    jQuery.ajax({
    type: "POST",
    url: vmsUrl,
    headers: { 'Prefer' : 'persistent-auth' },
    data: data1.toJsonString(),
    contentType: "application/json; charset=utf-8",
    dataType: "json",

    success: function (data, status, jqXHR) {
    alert('VM created successfully');

    },

    error: function (jqXHR, status) {
    // Showing the error
    alert(JSON.stringify(jqXHR));

    // Hiding the progress widget
    }
    });

    // Showing the progress widget
    }


    but above code is not working.Neither success message is printed nor error message.

    ReplyDelete
  6. This plugin doesn't appear to work any longer. There is no data center listed or cluster listed in the dropdown boxes on the docker creation page.

    ReplyDelete
    Replies
    1. That's true. Many things changed since, and it is no longer maintained.

      Delete
  7. Your information is really superb thanks for sharing good information share more content on Devops Online Training Bangalore

    ReplyDelete
  8. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating Docker training

    ReplyDelete
  9. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. devops online training

    ReplyDelete
  10. Really it is very useful for us..... the information that you have shared is really useful for everyone.Nice article i have ever read information's like this.it's really awesome the way you have delivered your ideas.i hope you will add more content in your blog PHP Training in Chennai | Certification | Online Training Course | Machine Learning Training in Chennai | Certification | Online Training Course | iOT Training in Chennai | Certification | Online Training Course | Blockchain Training in Chennai | Certification | Online Training Course | Open Stack Training in Chennai |
    Certification | Online Training Course

    ReplyDelete
  11. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    devops online training
    best devops online training
    top devops online training

    ReplyDelete
  12. toptan iç giyim tercih etmenizin sebebi kaliteyi ucuza satın alabilmektir. Ürünler yine orjinaldir ve size sorun yaşatmaz. Yine de bilinen tekstil markalarını tercih etmelisiniz.

    Digitürk başvuru güncel adresine hoşgeldiniz. Hemen başvuru yaparsanız anında kurulum yapmaktayız.

    tutku iç giyim Türkiye'nin önde gelen iç giyim markalarından birisi olmasının yanı sıra en çok satan markalardan birisidir. Ürünleri hem çok kalitelidir hem de pamuk kullanımı daha fazladır.

    nbb sütyen hem kaliteli hem de uygun fiyatlı sütyenler üretmektedir. Sütyene ek olarak sütyen takımı ve jartiyer gibi ürünleri de mevcuttur. Özellikle Avrupa ve Orta Doğu'da çokça tercih edilmektedir.

    yeni inci sütyen kaliteyi ucuz olarak sizlere ulaştırmaktadır. Çok çeşitli sütyen varyantları mevcuttur. iç giyime damga vuran markalardan biridir ve genellikle Avrupa'da ismi sıklıkla duyulur.

    iç giyim ürünlerine her zaman dikkat etmemiz gerekmektedir. Üretimde kullanılan malzemelerin kullanım oranları, kumaşın esnekliği, çekmezlik testi gibi birçok unsuru aynı anda değerlendirerek seçim yapmalıyız.

    iç giyim bayanların erkeklere göre daha dikkatli oldukları bir alandır. Erkeklere göre daha özenli ve daha seçici davranırlar. Biliyorlar ki iç giyimde kullandıkları şeyler kafalarındaki ve ruhlarındaki özellikleri dışa vururlar.

    ReplyDelete
  13. Ucuz, kaliteli ve organik sosyal medya hizmetleri satın almak için Ravje Medyayı tercih edebilir ve sosyal medya hesaplarını hızla büyütebilirsin. Ravje Medya ile sosyal medya hesaplarını organik ve gerçek kişiler ile geliştirebilir, kişisel ya da ticari hesapların için Ravje Medyayı tercih edebilirsin. Ravje Medya internet sitesine giriş yapmak için hemen tıkla: ravje.com

    İnstagram takipçi satın almak için Ravje Medya hizmetlerini tercih edebilir, güvenilir ve gerçek takipçilere Ravje Medya ile ulaşabilirsin. İnstagram takipçi satın almak artık Ravje Medya ile oldukça güvenilir. Hemen instagram takipçi satın almak için Ravje Medyanın ilgili sayfasını ziyaret et: instagram takipçi satın al

    Tiktok takipçi satın al istiyorsan tercihini Ravje Medya yap! Ravje Medya uzman kadrosu ve profesyonel ekibi ile sizlere Tiktok takipçi satın alma hizmetide sunmaktadır. Tiktok takipçi satın almak için hemen tıkla: tiktok takipçi satın al

    İnstagram beğeni satın almak için Ravje medya instagram beğeni satın al sayfasına giriş yap, hızlı ve kaliteli instagram beğeni satın al: instagram beğeni satın al

    Youtube izlenme satın al sayfası ile hemen youtube izlenme satın al! Ravje medya kalitesi ile hemen youtube izlenme satın almak için tıklayın: youtube izlenme satın al

    Twitter takipçi satın almak istiyorsan Ravje medya twitter takipçi satın al sayfasına tıkla, Ravje medya güvencesi ile organik twitter takipçi satın al: twitter takipçi satın al

    ReplyDelete