Dec 5, 2016

Instaling Ansible on Linux and Mac OS X

Ansible today is the new buzzword in world of DevOps because it allows sysadmins to easily and quickly transform their manual tasks into scripts for automated environment. The best thing about Ansible is that it is easy to learn, is agent less and doesn't require a lot of configuration to make the tool run. 

Apart from being a tool for sysadmins Ansible can be easily learn and put into practice by any developer with the same ease because of its clear syntax, structure and very wide support from open source community. As per Ansible website there are around 2200 contributors out there creating plugins for Ansible, so most probably there's already a solution to the problem or task. 

In this article we will look into installation of Ansible on different OS's and Docker.

Lets begin:

Latest release via YUM:

$ yum install ansible

Latest release via APT(ubuntu)

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

Latest release via APT (debian)

$ deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main
$ apt-get install ansible

Latest release on MAC OS X
$ sudo easy_install pip
$ pip install ansible


Dec 1, 2016

Docker Cheatsheet - Handy Docker commands for everyday use.


Docker is a container management system that helps easily manage Linux Containers. It lets us create images in virtual environments on our laptop or development environments. The actions that we do on containers and its corresponding behaviour remains same when we run them in production environment.


Docker Commands :

$docker --help : It gives full list of all Docker commands.

$docker <COMMAND> --help : To get additional help pertaining for the given command.

$docker version : gives the information about docker installation.

Search Docker Images :

$docker search <search-term> for e.g docker search nginx

Pulling a Docker Image:

$docker pull tutum/ubuntu

List Docker Images :

$docker images

       

Remove Docker Image:

$docker rmi ubuntu:trusty

Run a Docker Image:

$docker run -i -t image_name:tag /bin/bash 
-i gives an interactive shell
-t will assign a pseudo-tty

Run Docker Image as Daemon
<pre>
$docker run -d image_name:tag for e.g. $docker run -d ubuntu:trusty
</pre>
View the running container/s:
$docker ps

Expose the Docker ports in Daemon mode
$docker run -d -p 8080:80 ubuntu:trusty (port 8080 of container is mapped to port 80 of host)

Check the logs of Docker Container
$docker logs container_id or name

Kill a Docker Container:
$docker kill container_id or name

Stop a Docker Container:
$docker stop container_id or name

Get the stats of Docker Container:
$docker stats container_name

$docker top container_name

Remove the container
$docker rm container_name

BUILDING A DOCKER IMAGE
$docker build --help 

$docker build -f path_to_Dockerfile -t REPOSITORY:TAG
REPOSITORY mostly username is used for Docker Hub and <TAG> is the container name.

Building with multiple config files

Create a new directory to hold config files and CD into that directory before executing the build command.

$docker build -t REPOSITORY:TAG


DATA VOLUMES

Mounting a single volume
$docker run -it -v /user/home ubuntu /bin/bash

Mounting multiple volumes 
$docker run -it -v /user/home -v /tmp ubuntu /bin/bash

Mounting local directory inside the Docker Container
$docker run -it -v /user/home:/data ubuntu /bin/bash

Mounting in Read Only mode
$docker run -it -v /user/home:/data:ro ubuntu /bin/bash

We can verify the mounts by issuing :
$docker inspect container_id

DATA VOLUMES CONTAINER