Thursday, May 3, 2018

Download, Install and Delete Docker Container


Previous post Beginners Guide To Docker has covered the beginners guide to dockers. In this post, I will be covering more hands on experience. Before we start, I want you to check the previous post and make sure that the docker is up and running. Open a new terminal and type the following command
        

PS C:\windows\system32> docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE


Download and Installing Docker Image

We can see that there are no images installed locally on the laptop. Let's download a image from the docker public registry which is nothing but docker hub. We need to pull the image first from the docker hub and it will get stored on the local pc.
        
PS C:\windows\system32> docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latest
PS C:\windows\system32>


Once the image is downloaded, we can check the image is locally downloaded by running below mentioned command.
        

PS C:\windows\system32> docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
hello-world                latest              e38bc07ac18e        3 weeks ago         1.85kB
PS C:\windows\system32>

Once the image is downloaded, we can run the image locally and test it with below mentioned command.
        
PS C:\windows\system32> docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/


Let's try to run another container "centos" with a different process running inside it. Type the following command into your Terminal. The container image we're using is centos and the process we're executing inside the centos container is ping -c 5 127.0.0.1, which pings the loopback address for five times until it stops.
        
PS C:\windows\system32> docker run centos ping -c 5 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.028 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.029 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.028 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.042 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.026 ms

--- 127.0.0.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4198ms
rtt min/avg/max/mdev = 0.026/0.030/0.042/0.008 ms

Check The List Of Containers

Let's try to run another command to see the number of containers running on docker host.
        
PS C:\windows\system32> docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS         NAMES

By default docker gives 7 outputs once we run the container list command as below mentioned:
Container ID: Unique container ID with SHA-256
Image: Name of container image
Command: The command that is used to run the main process within container
Created: The date and time when the container was created
Status: running, removing, paused, exited
Ports: List of container ports that are mapped to docker host ports
Names: The random or manual name assigned to container

Run the below command to check the total number of containers defined in the system. The state of the container could be running, paused or exited
        
PS C:\windows\system32> docker ps -a
CONTAINER ID        IMAGE               COMMAND                 CREATED             STATUS                         PORTS               NAMES
f4912175410c        centos              "ping -c 5 127.0.0.1"   17 minutes ago      Exited (0) 17 minutes ago                          elastic_carson
b5f21082398a        centos              "ping -c 127.0.0.1"     17 minutes ago      Exited (2) 17 minutes ago                          confident_goldstine
dfebc236e05f        centos              "/etc/*release*"        18 minutes ago      Created                                            priceless_allen
9efc9e9ef4ae        centos              "ifconfig -a"           18 minutes ago      Created                                            hungry_hugle
e1f841554ff7        centos              "ping -c 2 4.2.2.2"     19 minutes ago      Exited (1) 19 minutes ago                          compassionate_payne
545dd4830c2b        hello-world         "/hello"                About an hour ago   Exited (0) About an hour ago                       wizardly_feynman

Deleting Containers

With the above command we know the container id, now let's run the below command in terminal and remove the container f4912175410c. Removing container doesn't mean we are removing the image, it's only meaning that we are removing it from the volume.
        
PS C:\windows\system32> docker rm f4912175410c
f4912175410c
PS C:\windows\system32> docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS                         PORTS               NAMES
b5f21082398a        centos              "ping -c 127.0.0.1"   22 minutes ago      Exited (2) 22 minutes ago                          confident_goldstine
dfebc236e05f        centos              "/etc/*release*"      22 minutes ago      Created                                            priceless_allen
9efc9e9ef4ae        centos              "ifconfig -a"         23 minutes ago      Created                                            hungry_hugle
e1f841554ff7        centos              "ping -c 2 4.2.2.2"   23 minutes ago      Exited (1) 23 minutes ago                          compassionate_payne
545dd4830c2b        hello-world         "/hello"              About an hour ago   Exited (0) About an hour ago                       wizardly_feynman

We can also remove multiple container in single command as per their status listed the above output. Let's try to run the below mentioned command in terminal and delete the containers whose status is showing "exited" as per the above output:
        
PS C:\windows\system32> docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS                         PORTS               NAMES
b5f21082398a        centos              "ping -c 127.0.0.1"   26 minutes ago      Exited (2) 26 minutes ago                          confident_goldstine
dfebc236e05f        centos              "/etc/*release*"      26 minutes ago      Created                                            priceless_allen
9efc9e9ef4ae        centos              "ifconfig -a"         27 minutes ago      Created                                            hungry_hugle
e1f841554ff7        centos              "ping -c 2 4.2.2.2"   27 minutes ago      Exited (1) 27 minutes ago                          compassionate_payne
545dd4830c2b        hello-world         "/hello"              About an hour ago   Exited (0) About an hour ago                       wizardly_feynman
PS C:\windows\system32>
PS C:\windows\system32> docker rm $(docker ps -q -f status=exited)
b5f21082398a
e1f841554ff7
545dd4830c2b
PS C:\windows\system32>
PS C:\windows\system32> docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
dfebc236e05f        centos              "/etc/*release*"    26 minutes ago      Created                                 priceless_allen
9efc9e9ef4ae        centos              "ifconfig -a"       27 minutes ago      Created                                 hungry_hugle
PS C:\windows\system32>


Click Here To Read Rest Of The Post...

Wednesday, May 2, 2018

Beginners Guide To Docker


Docker comes into two different kind of flavors community edition(CE) and enterprise edition(EE). Community edition can be downloaded by anyone and can be used for development and testing purpose without any professional support. Enterprise Edition comes with yearly based license and backed by 24 x 7 support and are supported with bug fixes much longer than their community edition.

Food For Thought: Learn More About Docker Security

Docker Architecture
Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface.

Docker client interacts with docker daemon by sending the commands, Docker daemon listems for Docker API's request and manages images, volumes and networks. Docker registry is the place where the docker images get stored. docker hub is the ppular cloud based registry to host the docker images.

Docker is written in GO which open source programming language. Docker uses a technology called namespaces to provide the isolated workspace called the container. When you run a container, Docker creates a set of namespaces for that container. These namespaces provide a layer of isolation. Each aspect of a container runs in a separate namespace and its access is limited to that namespace.

Docker Installation On Windows
Docker can be installed on linux, mac or windows. In this post, I will be using the windows10 machine for docker installation. Docker Community Edition can be downloaded from the https://docs.docker.com/docker-for-windows/install/. Once the installtion is done, you can run the shortcut "Docker For Windows" on your desktop. In the power shell, you can rnu the below command to check the version of the installed docker.

        

PS C:\windows\system32> docker --version
Docker version 18.03.1-ce, build 9ee9f40
PS C:\windows\system32>


In the next post, I will be covering more hands on exercise on dockers.
References: Docker Website

Click Here To Read Rest Of The Post...

Tuesday, May 1, 2018

Brief About Docker Containers


Linux container aka LXC is a copy of a Linux environment located in a file system which is like a chroot environment but uses Linux NameSpaces, runs its own seperate process, seperate file system and separate network stack which is virtualized by the underneath operating system. The underneath opearting system could be from linux or from windows.

In nutshell, we are doing Operating-system-level virtualization which is also known as containerization. The process is nothing but running multiple isolated Linux Systems (Containers) on a control host using single Linux Kernal. It also refers to an operating system feature in which the kernel allows the existence of multiple isolated user-space instances. Such instances, called containers,partitions, virtualization engines (VEs) or jails (FreeBSD jail or chroot jail), may look like real computers from the point of view of programs running in them. A computer program running on an ordinary operating system can see all resources (connected devices, files and folders, network shares, CPU power, quantifiable hardware capabilities) of that computer. However, programs running inside a container can only see the container's contents and devices assigned to the container.

What is Docker Container?
Docker is one of the most successful open source container project in recent history, and organizations of all sizes are developing plans around how to containerize their applications. Docker came in 2013, when the code, invented by Solomon Hykes, was released as open source. The docker's approach is especially for cloud applications and agile development because many different applications can run on top of a single OS instance, this can be a more efficient way to run applications. Containers speeds up applications development and testing, because software developers don’t have to worry about shipping special versions of the code for different operating systems. Because of the lightweight nature of its containers, the approach can also improve the portability of applications. Containers are an efficient and fast way to move pieces of software around in the cloud.

Difference Between VM and Container
In a VM-centered world, the unit of abstraction is a monolithic VM that stores not only application code, but often the stateful data. A VM takes everything that used to sit on a physical server and just packs it into a single binary so it can be moved around. But it is still the same thing. With Docker containers the abstraction is the application; or more accurately a service that helps to make up the application.

In a micro-services architecture, many small services (each represented as a single Docker container) comprise an application. Applications are now able to be deconstructed into much smaller components which fundamentally changes the way they are initially developed, and then managed in production.

References: SDX Central and Dockers

Click Here To Read Rest Of The Post...