The DevOps Se­ries Us­ing Docker with An­si­ble

This ar­ti­cle is the eighth in the DevOps se­ries. This month, we shall learn to set up Docker in the host sys­tem and use it with An­si­ble.

OpenSource For You - - Fossbytes -

Docker pro­vides op­er­at­ing sys­tem level vir­tu­al­i­sa­tion in the form of con­tain­ers. These con­tain­ers al­low you to run stand­alone ap­pli­ca­tions in an iso­lated en­vi­ron­ment. The three im­por­tant fea­tures of Docker con­tain­ers are iso­la­tion, porta­bil­ity and re­peata­bil­ity. All along we have used Parabola GNU/Linux-li­bre as the host sys­tem, and ex­e­cuted An­si­ble scripts on tar­get vir­tual ma­chines (VM) such as Cen­tOS and Ubuntu.

Docker con­tain­ers are ex­tremely light­weight and fast to launch. You can also spec­ify the amount of re­sources that you need such as the CPU, mem­ory and net­work. The Docker tech­nol­ogy was launched in 2013, and re­leased un­der the Apache 2.0 li­cence. It is im­ple­mented us­ing the Go pro­gram­ming lan­guage. A num­ber of frame­works have been built on top of Docker for man­ag­ing these clus­ters of servers. The Apache Me­sos project, Google’s Ku­ber­netes, and the Docker Swarm project are pop­u­lar ex­am­ples. These are ideal for run­ning state­less ap­pli­ca­tions and help you to eas­ily scale hor­i­zon­tally.

Set­ting it up

The An­si­ble ver­sion used on the host sys­tem (Parabola GNU/Linux-li­bre x86_64) is 2.3.0.0. In­ter­net ac­cess should be avail­able on the host sys­tem. The an­si­ble/ folder con­tains the fol­low­ing file: an­si­ble/play­books/con­fig­u­ra­tion/docker.yml

In­stal­la­tion

The fol­low­ing play­book is used to in­stall Docker on the host sys­tem:

--name: Setup Docker hosts: lo­cal­host gath­er_­facts: true be­come: true tags: [setup]

tasks:

- name: Up­date the soft­ware pack­age repos­i­tory pac­man: up­date_­cache: yes

- name: In­stall de­pen­den­cies pack­age: name: “{{ item }}” state: latest

with­_items: - python2-docker - docker

- ser­vice: name: docker state: started

- name: Run the hello-world con­tainer dock­er_­con­tainer: name: hello-world im­age: li­brary/hello-world

The Parabola pack­age repos­i­tory is up­dated be­fore pro­ceed­ing to in­stall the de­pen­den­cies. The python2-docker pack­age is re­quired for use with An­si­ble. Hence, it is in­stalled along with the docker pack­age. The Docker dae­mon ser­vice is then started and the li­brary/hello-world con­tainer is fetched and ex­e­cuted. A sam­ple in­vo­ca­tion and ex­e­cu­tion of the above play­book is shown be­low:

$ an­si­ble-play­book play­books/con­fig­u­ra­tion/docker.yml -K --tags=setup

SUDO pass­word:

PLAY [Setup Docker] *****************************************

TASK [Gath­er­ing Facts] ************************************** ok: [lo­cal­host]

TASK [Up­date the soft­ware pack­age repos­i­tory] *************** changed: [lo­cal­host]

TASK [In­stall de­pen­den­cies] ********************************* ok: [lo­cal­host] => (item=python2-docker) ok: [lo­cal­host] => (item=docker)

TASK [ser­vice] ********************************************** ok: [lo­cal­host]

TASK [Run the hello-world con­tainer] ************************ changed: [lo­cal­host]

PLAY RE­CAP ************************************************** lo­cal­host : ok=5 changed=2 un­reach­able=0 failed=0

With the ver­bose ‘-v’ op­tion to an­si­ble-play­book, you will see an en­try for LogPath, such as /var/lib/docker/ con­tain­ers/<con­tainer-id>/<con­tainer-id>-json.log. In this log file, you will see the out­put of the ex­e­cu­tion of the hel­loworld con­tainer. This out­put is the same when you run the con­tainer man­u­ally as shown be­low:

$ sudo docker run hello-world Hello from Docker!

This mes­sage shows that your in­stal­la­tion ap­pears to be work­ing cor­rectly.

To gen­er­ate this mes­sage, Docker took the fol­low­ing steps:

1. The Docker client con­tacted the Docker dae­mon.

2. The Docker dae­mon pulled the hello-world im­age from the Docker Hub.

3. The Docker dae­mon cre­ated a new con­tainer from that im­age, which runs the ex­e­cutable that pro­duces the out­put you are cur­rently read­ing.

4. The Docker dae­mon streamed that out­put to the Docker client, which sent it to your ter­mi­nal.

To try some­thing more am­bi­tious, you can run an Ubuntu con­tainer with:

$ docker run -it ubuntu bash

You can share images, au­to­mate work­flows, and more with a free Docker ID at https://cloud.docker.com/.

For more ex­am­ples and ideas, do visit https://docs.docker. com/engine/user­guide/.

An ex­am­ple

A deep learn­ing (DL) Docker project is avail­able (https://github.com/floy­d­hub/dl­docker) with sup­port for frame­works, li­braries and soft­ware tools. We can use An­si­ble to build the en­tire DL con­tainer from the source code of the tools. The base OS of the con­tainer is Ubuntu 14.04, and will in­clude the fol­low­ing soft­ware pack­ages: Ten­sorFlow

Caffe

Theano

Keras

Lasagne

Torch iPython/Jupyter Note­book

Numpy

SciPy

Pan­das

Scikit Learn

Mat­plotlib

OpenCV

The play­book to build the DL Docker im­age is given be­low:

- name: Build the dl-docker im­age hosts: lo­cal­host gath­er_­facts: true be­come: true tags: [deep-learn­ing]

vars:

DL_BUILD_DIR: “/tmp/dl-docker” DL_DOCKER_NAME: “floy­d­hub/dl-docker”

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.