Tuesday, October 31, 2017

5. Docker Hub

 Docker Hub:-

Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities. You can also upload your own Docker built images to Docker hub. In this chapter, we will see how to download and the use the Jenkins Docker image from Docker hub.



The official site for Docker hub is: https://www.docker.com/products/docker-hub
Step 1: First you need to do a simple sign-up on Docker hub.



Step 2: Once you have signed up, you will be logged into Docker Hub.
Step 3: Next, let’s browse and find the Jenkins image.


Step 4: If you scroll down on the same page, you can see the Docker pull command. This will be used to download the Jenkins image onto the local Ubuntu server.



Step 5: Now, go to the Ubuntu server and run the following command:
                  #sudo docker pull jenkins

                       














To run Jenkins, you need to run the following command:
#sudo docker run -p 8080:8080 -p 50000:50000 jenkins
  • Note the following points about the above sudo command:
  •  We are using the sudo command to ensure it runs with root access
  • Here, jenkins is the name of the image we want to download from Docker hub and install on our Ubuntu machine. 
  • -p is used to map the port number of the internal Docker image to our main Ubuntu server so that we can access the container accordingly.

  • You will then have Jenkins successfully running as a container on the Ubuntu machine.



For More Information Of Docker :-
Reference

4. Docker Architecture (Docker vs Virtualization)

                                         

Docker Architecture 

(Docker vs Virtualization) 



Virtualization :-  The following image shows the standard and traditional architecture of virtualization it could be a Bare Metal hypervisor or Hosted Hypervisor anyone..


1. The server is the physical server that is used to host multiple virtual machines.
2. The Host OS is the base machine such as Linux or Windows in case of Hosted.
3. The Hypervisor is either VMWare or Windows Hyper V that is used to host virtual machines.
4. You would then install multiple operating systems as virtual machines on top of the existing hypervisor as Guest OS
5. You would then host your applications on top of each Guest OS.

Docker :- 
The following image shows the new generation of virtualization that is enabled via Dockers.Let’s have a look at the various layers.


1. The server is the physical server that is used to host multiple virtual machine.
2. The host OS is base machine such linux or windows. So this layer remains same.
3. On top of OS we use to deploy the Docker Engine.
4. Than make a container and run the applications.
5. The main advantage in this architecture is that you don't need to have extra hardware for GUEST OS.

Docker architecture:- 


Docker user 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.


The Docker daemon:- 

The docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks nad volumes. A daemon can also communicate with other daemons to manage Docker services.





Docker Client:-
The Docker client (docker) is the primary way that many Docker users interact with Docker. When you use commands such as docker run, the
Client sends these commands to dockerd, which carries tham out.
The docker command user the Docker API. The Docker client can communicate with more than one daemon.

CONTAINERS:- A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.

   By default, a container is relatively well isolated from other containers and its host machine. You can control how isolated a container’s network, storage, or other underlying subsystems are from other containers or from the host machine. 

   A container is defined by its image as well as any configuration options you provide to it when you create or start it. When a container is removed, any changes to its state that are not stored in persistent storage disappear.


Docker Engine:- Docker Engine is a client-server application with these major components. 

* A server which is a type of long-running program called a daemon process (the dockerd command). 
* A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do.
* A command line interface (CLI) client (the docker command).



The CLI uses the Docker REST API to control or interact with the Docker daemon through scripting or direct CLI commands. Many other Docker applications use the underlying API and CLI.

The daemon creates and manages Docker objects, such as images, containers, networks, and volumes.

Monday, October 30, 2017

3. Basic Elements of Docker Technology



                     3.  Basic Elements of Docker Technology


1. Docker image: Docker images are the basis of containers. An Image is an ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime. An image typically contains a union of layered filesystems stacked on top of each other. An image does not have state and it never changes.
Pic. 1.0
 2.  Container: A container is a runtime instance of a Docker image. A Docker container consists of: A Docker image, an execution environment and a standard set of instructions. The concept is borrowed from Shipping Containers, which define a standard to ship goods globally. Docker defines a standard to ship software.Usually, a container will “contain” something singular from a functional point of view, like a service, a microservice or a more monolithic application process. It is a 1:1 relationship. For instance, each microservice process would “be” a single container, too.

Pic. 2.0
3. Repository: A repository is a set of Docker images. A repository can be shared by pushing it to a registry server. The different images in the repository can be labeled using tags.
Pic.2.1
4. Registry:Registry is a hosted service containing repositories of images which responds to the Registry API. The default registry (from Docker as an organization) can be accessed using a browser at Docker Hub or using the docker search command.
Pic. 3.0
5. Docker Hub: The Docker Hub is a centralized resource for working with Docker and its components. It provides the following services: Docker image hosting, User authentication, Automated image builds plus work-flow tools such as build triggers and web hooks, Integration with GitHub and Bitbucket.
Pic. 4.0

6.  Docker Trusted Registry
:
 Docker Trusted Registry (DTR) is the enterprise-grade image storage solution from Docker. You install it behind your firewall so that you can securely store and manage the Docker images you use in your applications. Docker Trusted Registry is a suc-product included as part of the Docker Datacenter product.

Sunday, October 29, 2017

2. Docker Installation on Linux Machine

2.  Docker Installation on Linux Machine

To start the installation of Docker, we are going to use an Ubuntu instance. You can use Oracle Virtual Box to setup a virtual Linux instance, in case you don’t have it already.

The following screenshot shows a simple Ubuntu server which has been installed on Oracle Virtual Box. There is an OS user named demo which has been defined on the system having entire root access to the sever.



 To install Docker, we need to follow the steps given below.

Step 1: Before installing Docker, you first have to ensure that you have the right Linux kernel version running. Docker is only designed to run on Linux kernel version 3.8 and higher. We can do this by running the following command:

uname

This method returns the system information about the Linux system.

Syntax

uname -a


Options

a This is used to ensure that the system information is returned.

Return Value

This method returns the following information on the Linux system:

·         kernel name

·         node name

·         kernel release

·         kernel version

·         machine

·         processor

·         hardware platform

·         operating system

Example


uname –a

Output

When we run above command, we will get the following result:

 From the output, we can see that the Linux kernel version is 4.2.0-27 which is higher than version 3.8, so we are good to go.


Step 2: You need to update the OS with the latest packages, which can be done via the following command:

apt-get

This method installs packages from the Internet on to the Linux system.

Syntax

sudo apt-get update


Options

·         sudo - The sudo command is used to ensure that the command runs with root access.

·         update - The update option is used ensure that all packages are updated on the Linux system.

Return Value

None

Example

sudo apt-get update


Output

When we run the above command, we will get the following result:



 This command will connect to the internet and download the latest system packages for Ubuntu.


Step 3: The next step is to install the necessary certificates that will be required to work with the Docker site later on to download the necessary Docker packages. It can be done with the following command:

sudo apt-get install apt-transport-https ca-certificates 


Step 4: The next step is to add the new GPG key. This key is required to ensure that all data is encrypted when downloading the necessary packages for Docker.

The         following          command         will          download          the         key         with          the         ID

58118E89F3A912897C070ADBF76221572C52609D from the keyserver hkp://ha.pool.sks-keyservers.net:80 and adds it to the adv keychain. Please note that this particular key is required to download the necessary Docker packages.

sudo apt-key adv \

--keyserver hkp://ha.pool.sks-keyservers.net:80 \

--recv-keys 58118E89F3A912897C070ADBF76221572C52609D






  
Step 5: Next, depending on the version of Ubuntu you have, you will need to add the relevant site to the docker.list for the apt package manager, so that it will be able to detect the Docker packages from the Docker site and download them accordingly.

·         Precise 12.04 (LTS) ─ deb https://apt.dockerproject.org/repo ubuntu-precise main

·         Trusty 14.04 (LTS) ─ deb https://apt.dockerproject.org/repo ubuntu-trusty main

·         Wily 15.10 ─ deb https://apt.dockerproject.org/repo ubuntu-wily main

·         Xenial 16.04 (LTS) ─ deb https://apt.dockerproject.org/repo ubuntu-xenial main

Since our OS is Ubuntu 14.04, we will use the Repository name as “deb https://apt.dockerproject.org/repo ubuntu-trusty main”

And then, we will need to add this repository to the docker.list as mentioned above.

echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main” |sudo
 tee /etc/apt/sources.list.d/docker.list




  


Step 6: Next, we issue the apt-get update command to update the packages on the Ubuntu system.



 Step 7: If you want to verify that the package manager is pointing to the right repository, you can do it by issuing the apt-cache command.

apt-cache policy docker-engine

In the output, you will get the link to https://apt.dockerproject.org/repo/








Step 8: Issue the apt-get update command to ensure all the packages on the local system are up to date.





Step 9: For Ubuntu Trusty, Wily, and Xenial, we have to install the linux-image-extra-* kernel packages, which allows one to use the aufs storage driver. This driver is used by the newer versions of Docker.

It can be done by using the following command:

 
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual






 Step 10: The final step is to install Docker and we can do this with the following command:

sudo apt-get install –y docker-engine

Here, apt-get uses the install option to download the Docker-engine image from the Docker website and get Docker installed.

The Docker-engine is the official package from the Docker Corporation for Ubuntu-based systems.








 Docker Version-

To see the version of Docker running, you can issue the following command:

Syntax

docker version


Options

·         version It is used to ensure the Docker command returns the Docker version installed.

Return Value

The output will provide the various details of the Docker version installed on the system.

Example

sudo docker version

Output

When we run the above program, we will get the following result:





 Docker Info

To see more information on the Docker running on the system, you can issue the following command:

Syntax

docker info


Options

·         info It is used to ensure that the Docker command returns the detailed information on the Docker service installed.

Return Value

The output will provide the various details of the Docker installed on the system such as

·         Number of containers

·         Number of images

·         The storage driver used by Docker

·         The root directory used by Docker

·         The execution driver used by Docker

Example

sudo docker info

Output

When we run the above command, we will get the following result:






9. Docker container networking

                                Docker container networking          Docker takes care of the networking aspects so that the containers c...