Docker

DOCKER

What is docker?

Docker is a container management service and is an open platform for developing, shipping and
running applications. It separate the applications from the infrastructure so it easy to deliver software quickly.

Why Docker?
If we will go back and see the container in software development , at that time when we develop an application, we need to provide our code alongside with all possible dependencies like libraries, web server, databases, etc. So if the application is running in our computer and this running application we want to start it on stage server, dev or a QA machine again we have to configure all the dependencies with the application.

This challenge can be short out by isolating the app to make it independent of the system.
Now Virtual machines came in figure. To avoid the above problem traditional virtual machines were used. The main problem with the is that "extra OS" on top of host operating systems that took gigabytes of space to the project. And to deploy the app for different environments like staging, dev, QA our server will host several VMs that will take even more space. And by the way, if the same we host in cloud-based server; at that moment the cloud-based server providers will charge you for that extra space. Another drawback of the VM is a slow boot.

Docker eliminates all the above by simply sharing OS kernel across all the containers that are running as separate processes of the host OS.

Docker streamlines the development lifecycle by allowing the developers to work in a standardized environments. Consider the some scenario:

 1- Developers can write code locally and share their work with their colleagues using docker containers.

2- They can use the Docker to push their application into a test environment and execute automated and manual tests.

3- When the developers if find any bugs, they can fix them in the development environment and redeploy them to the test environment for testing and validations.

4- When the testing is complete, getting the fix to the customer is a simple as pushing the updated image to the production environment.

DOCKER ARCHITECTURE 







-> It is a client-server architecture.
-> The Docker client talks to the docker daemon(shown in fig), which does the heavy lifting of building, running and distributing Docker container. The both Docker client and Docker daemon they communicate to each other by using REST API over unix sockets or network interface.

Docker daemon : (dockerd) listens for Docker API requests and manages the docker objects such as images, containers, network and volumes.

Docker Client : Whenever we send the command like docker run , the client send these commands to dockerd. Internally docker command uses the Docker API.

Docker Registries: It stores the docker images. Docker have two public registries Docker Hub(default configured) and Docker Cloud

Images(like VM) : An image is combination of a file system and parameters.

Container(running machines) : Container is an instance of an Docker image. You can create, delete, run , stop or move a container using the Docker API or CLI.

INSTALLATION

On Linux machine:
Step 1 - Check the Linux version using blow command:
                uname -a
               The Linux kernal version should be 3.8 or higher
Step 2 - Update the OS with latest package
              sudo apt-get update
Step 3 - Install the necessary certificates that will required to work with docker site later.
              sudo apt-get install apt-transport-https ca-certificates
Step 4 - Add the new GPG keys. This keys is required to ensure that that the data has encrypted                        while downloading the packages from the server.
              sudo apt-key adv \  
             --keyserver hkp://ha.pool.sks-keyservers.net:80 \  
             --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Step 5-  Run the below command, it will substitute the entry for your OS.
              echo "<REPO>" | sudo tee /etc/apt/sources.list.d/docker.list
Step 6 - Open the file /etc/apt/sources.list.d/docker.list. Copy- Paste the below line into this file
              deb https://apt.dockerproject.org/repo ubuntu-xenial main
Step 7 - Update the package again
             sudo atp-get update
Step 8 - Verify the APT is pulling from the correct repository
              apt-cache policy docker-engine
Step 9 - Install the packages
             sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
Step 10 - Install the docker engine
                sudo apt-get update
                sudo apt-get install docker-engine
Step 11 - Start the docker daemon and verify docker has installed correctly
               sudo service docker start
               sudo docker run hey-brotha


Basic Commands:


To check the image details  :           sudo docker images
To create the container  :                 sudo docker run –it <image>:<tag>
To check the container status :       sudo docker ps –a
List of all the running containers:  sudo docker ps
List container that was launched a few minutes ago: sudo docker ps -all
To start the container   :     sudo docker start <containerID>
To stop the container   :     sudo docker stop <containerID>
To remove the container  :  sudo docker rm <containerID>
To remove all containers  :  docker rm -f $(docker ps -aq)
To attach to a running Container via the docker attach command  :  sudo docker attach <containerID>

NOTE:       -i    for going into interactive mode

No comments:

Post a Comment