Steps to Build, Run and Manage Docker

Docker is a software container that automates the applications deployment while providing an additional layer of OS-level virtualization automation on Linux. These docker containers are created using docker images, either by executing commands manually or automatically through Dockerfiles.

According to an industry analyst research, Docker is an efficient tool that packs an application and its dependencies in a virtual container that can operate on any Linux server. This process facilitates the flexibility and portability where the application is running.

Docker avoids the burden of maintaining virtual machine by allowing independent containers to operate within a single Linux instance, using Linux kernel resource isolation features such as kernel namespaces and cgroups.

How Docker is different from Virtual Machines?

Though resource isolation and allocation benefits of docker containers are similar to virtual machines, the different architectural approach of containers makes them more portable and efficient.

Containers-vs-Virtual-Machines

Advantages of Docker

  • Easy to move apps between cloud platforms
  • Distribute and share content
  • Accelerate developer onboarding
  • Empower developer creativity
  • Eliminate environment inconsistencies
  • Ship software faster
  • Easy to scale an application
  • Remediate issues efficiently

Installing Docker on Ubuntu

Update the droplet

sudo aptitude    update
sudo aptitude -y upgrade

Make sure the availability of aufs support

sudo aptitude install linux-image-extra-`uname -r`

For package verification, add docker repository key to apt-key

sudo sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -"

Add the docker repository to aptitude sources

sudo sh -c "echo deb http://get.docker.io/ubuntu docker main\

> /etc/apt/sources.list.d/docker.list"

Update the repository with the new addition

sudo aptitude    update

Finally, download and install docker

sudo aptitude install lxc-docker

 

Proxy in Docker

Edit /etc/defaults/docker and add the following lines:

export http_proxy='http://proxy.vmoksha.com:8080'

After adding, restart the docker using the following comment:

$ sudo service docker restart

This will allow the docker daemon to pull images from central registry. However, to configure the proxy in Dockerfile (while using apt-get to install packages), you need to declare the comment there also.

Add the following lines at the top of your Dockerfile:

ENV http_proxy 'http://proxy.vmoksha.com:8080'

ENV https_proxy 'http://proxy.vmoksha.com:8080'

ENV HTTP_PROXY 'http://proxy.vmoksha.com:8080'

ENV HTTPS_PROXY 'http://proxy.vmoksha.com:8080'

With these settings, your container should now build using the proxy to access the
outside world

Basic Docker Commands

Running the docker in daemon and CLI Usage

Upon installation, the docker daemon that is running in the background will be ready to accept commands sent by the docker CLI. During certain situations like running a docker manually, it is necessary to follow the below guidelines:

Run the docker in daemon mode

sudo docker -d &

Docker CLI Usage

sudo docker [option] [command] [arguments]

Commands List

Check out the provided list of docker commands:

attach         Attach to a running container
build          Build a container from a Dockerfile
commit         Create a new image from a container's changes
cp             Copy files/folders from the containers filesystem to the host path
diff           Inspect changes on a container's filesystem
events         Get real time events from the server
export         Stream the contents of a container as a tar archive
history        Show the history of an image
images         List images
import         Create a new filesystem image from the contents of a tarball
info           Display system-wide information
insert         Insert a file in an image
inspect        Return low-level information on a container
kill           Kill a running container
load           Load an image from a tar archive
login          Register or Login to the docker registry server
logs           Fetch the logs of a container
port           Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
ps             List containers
pull           Pull an image or a repository from the docker registry server
push           Push an image or a repository to the docker registry server
restart        Restart a running container
rm             Remove one or more containers
rmi            Remove one or more images
run            Run a command in a new container
save           Save an image to a tar archive
search         Search for an image in the docker index
start          Start a stopped container
stop           Stop a running container
tag            Tag an image into a repository
top            Lookup the running processes of a container
version        Show the docker version information
wait           Block until a container stops, then print its exit code

 

Command2 Command1

Example 1: An Interactive Container of tomcat server

Let’s try the docker run command again, with specifying a new command to run in our container.

$ sudo docker run --name ubuntu14  –p 8080:8080 -t -i tutum/tomcat /bin/bash

-t → pseudo-tty or terminal inside our new container

-i → interactive connection by grabbing the standard in (STDIN) of the container

/bin/bash → This will launch a Bash shell inside our container

-p → Port exposing

So, now when our container is launched, we can see a command prompt inside it.

root@af8bae53bdd3:/#

 

Note: Change the port number of tomcat server in /tomcat/conf/server.xml file and restart the tomcat service in the container. Open the tomcat manager in a browser and deploy the applications.

Example 2: Run nginx container in the docker

To install and assign a port number for nginx, apply the following comment

docker run --name ngnix -p 81:81 -it nginx/nginx /bin/bash

Note: Change the default port number of ngnix server in /etc/nginx/sites-enabled/default file and restart the ngnix server.

To view the Docker monitor in a web browser:

Run the Docker UI command:

$ docker run -d -p 9000:9000 --privileged -v /var/run/docker.sock:/var/run/docker.sock dockerui/dockerui

To exit the container:

CTRL+P immediately followed by CTRL+Q

Committing changes to an image

To continue performing actions in a container such as download and install, configure files, etc. you need to “commit.” Committing ensures that everything (e.g. image) can be resumed during the next visit.

# Usage: sudo docker commit [container ID] [image name]

sudo docker commit 8dbd9e392a96 my_img

 

Export

sudo docker export <CONTAINER ID> > /home/export.tar

Note: If we export the container, it will not copy history and meta-data. Hence, the file size may be less than 5MB.

Save

$ sudo docker save busybox-1 > /home/save.tar

Note: It will save the container’s history and meta-data. Hence, the file size will be slightly more, when compared to export.

How to Limit the Memory Usage for Containers?

In order to limit the memory usage, simply set –m [memory amount] flag in a docker container.

To run a container with memory limited to 256 MBs:

# Example: docker run -name [name] -m [Memory (int)][memory unit (b, k, m or g)] -d (to run not to attach) -p (to set access and expose ports) [image ID]

docker run -m 64m -d -p 8082:80 tutum/wordpress

To confirm the memory limit, you can inspect the container:

# Example: docker inspect [container ID] | grep Memory

docker inspect 9a7562a361122706 | grep Memory

Hence, it is one of the major technology innovations, which provides enterprises with significant revenue improvements. It transforms the way you deploy, manage and migrating applications in the cloud and is always a right tool for your enterprise.

 

FacebookTwitterGoogle+Share
CCTV surveillance using Raspberry Pi

CCTV surveillance using Raspberry Pi

Overview

For Security purposes, we usually need to capture every motion in specified areas. To fulfill this requirement, CCTV cameras were introduced a few years ago.

However, this brought along some challenges such as the following:

  • The ordinary security cameras run continuously, in turn recording everything
  • They need to be monitored 24 hours a day
  • Another major problem with ordinary security cameras is that you need to fast-forward and rewind a lot to find a particular moment / situation

 

Vmoksha’s SolutionRaspberry-Pi
To overcome these issues, Motion activated cameras were introduced. These cameras do not record unless a specified minimum size moves within their range. It stores only potentially relevant video which makes easy to review a particular event.

 

Vmoksha has implemented CCTV Surveillance System by using Raspberry Pi. This system records every motion in a specified area, which can be monitored from any web browser. The camera connected to the Raspberry Pi module detects any kind of motion and capture images. The Raspberry Pi stores the images locally, converts them into a video and uploads that video into Cloud storage such as Dropbox

 

Block Diagram

Block Diagram

Components of the Raspberry Pi Module

Components of the Raspberry Pi Module

 

Hardware Components

Raspberry Pi: It is a credit-card sized low-cost computer that plugs into a TV or computer monitor and uses a standard keyboard and mouse.

Raspberry Pi Camera Module: It captures high-definition video and still photographs. It is also used to capture slow-motion, time-lapse and other videos.

Power Supply: Raspberry Pi has micro USB connectors to connect the power supply. The requirement for the power supply is 5V and 700mA although it is recommended to use a 1.2A power supply especially if you will be connecting wireless devices or a Wi-Fi dongle.

SD Card: The Raspberry Pi Operating System is loaded and executed from an SD card.

 

Software Components

Raspbian: To run the Raspberry Pi, we need an operating system which is a set of basic programs and utilities. Raspberry Pi foundation recommends installing the Raspbian operating system, a version of Debian Linux that optimizes and uses the Raspberry Pi hardware. This comes with over 35,000 packages, which makes it more than a pure OS. It is precompiled software bundled in an appropriate format for easy installation on your Raspberry Pi. It is still under active development with emphasis on improving the performance and stability of many Debian packages.

Motion Software: This program monitors the video signal from one or more cameras and detects motion. It is able to detect if a significant part of the picture has changed. It is basically made for Linux operating system and is a command line based tool whose output can be PPM, JPEG files or MPEG video sequences. It is the perfect tool to monitor your property because it saves only those images that are really required.

 

How does it work?

A Raspbian image is installed on the SD card and connected to the Raspberry Pi module. The motion software program has also to be installed after this.

The motion software program continuously compares every image with a previously captured image and detects motion. If it recognizes any difference between two images, it starts capturing image and stores those images on an SD card. When motion stops, it converts those captured images to a video.

The Raspberry Pi will then upload the converted videos to the Dropbox cloud storage and delete the uploaded video from SD card. For this uploading and deleting process, we have used Python code.

 

Challenges and Solutions

While implementing this project, we faced some challenges. Read on to know how we faced our challenges with smart solutions:

#

Challenge Solution

1

Initially, the converted videos were not uploading to Dropbox due to a proxy issue We provided full permission to Dropbox

2

Once the video is upload, it was showing up an incorrect time, hence we could not recognize the latest video We used timestamp in the Python code which attaches time to that video file while uploading

 

After a series of challenges and solutions, Vmoksha finally succeeded in implementing CCTV Surveillance by Using Raspberry PI.

 

My sincere thanks to Mehter M Muzzamil, who had also contributed and helped me in launching CCTV surveillance using Raspberry Pi module.