Q1:- What is docker ? Ans:- Docker is open source plateform for developers and system engineer to bulid, ship and run distributed applicat...

Docker Basics

Q1:- What is docker ?
Ans:- Docker is open source plateform for developers and system engineer to bulid, ship and run distributed application, whether on physical machine, vm, cloud. Docker is not a Linux container technology like Xen/KVM etc.
Docker provide an additional layer of abstraction and automation of operating system | virtualization on Windowa and Linux

Advantage of using Docker
==========================
Portability- In docker system, an application and its pre-req's/ dependencies can be bundled into a single container/image, which will be independent of host kernel, can be easily ported to different system.

Quik Application Deployment:- As application and it's dependencies can be bulid in single image, it make easy to quickly deploy the app.

Sharing:- you can share Docker Image with other using remote reposittories.

Lightweight:- Docker image very small, they need very low compute and storage...

Easy Maintenance:- Maintenance very quick and easy

Cost saving :- Open source Technology and don't need heavy compute

Docker containers Vs virtual Machine
=======================================

(1) Docker container can be created/deployed vary quickly as compare to virtual machine
(2) Docker container are light weight as compare to virtual machine, being light weight more container can run at same time to host
(3) Docker container make use of resources very effciently, in case of virtual machine capacity is need to be reserved (compute + storage), whereas this is not needed is case of docker container
(4) virtual machine can be migrated across servers when they are running, but docker need to be stoped before migration as there is no hypervisor layer

Docker Terminology
=====================
(1) Image:- Image are templates for the docker container
(2) Container:- Created from docker image and run the actual application
(3) Docker Daemon:- The background service on the host that manages buliding. running the container

Docker installation
====================

# yum install docker
# systemctl status docker
# systemctl start docker
# systemctl enable docker
# docker version==========check version
# docker info=============check details information of docker
# docker search centos====Search Dokcer image on internet

LAB Task
==========

Download Docker Image
# docker pull centos:centos7

To display the list of locally available images, types
#docker images

To test your new image
# docker run centos:centos7

List of docker container
#docker ps -a

checking docker networking
# docker network ls
# docker network inspact [network name]

Check Resource Consumption by running continer#
# docker status

Setting Resource limits for a docker container
# dokcer run it -c 256 -m 300M centos:centos7 /bin/bash

stop/start/Restart Operations
# docker start container ID
# docker stop container ID
# docker restart container ID

Commiting the Docker Container Updates (This command turns your container to an image)
# docker commit container ID

Adding a reposittories/Tag value to a image
# docker tag container ID

Remove/Delete a container
# docker rm container ID

checking the docker container logs
# docker logs container ID
===================================================================================
# docker version
#  docker info
#  docker search centos
#  docker search busybox
#  docker search centos7
#  docker pull centos:centos7
#  docker images
#  docker run centos:centos7 /bin/ping opera.com -c 5
#  docker run centos:centos7 uname -a
#  uname -a
#  docker -ps -a
#  docker ps -a
#  docker run centos:centos7 ifconfig -a
#  docker network ls
#  docker network inspect bridge
#  docker run -it -c 256 -m 300M centos:centos7 /bin/bash
#  docker ps -a
#  docker stop 3f1b22fabd95
#  docker start 3f1b22fabd95
#  docker restart 3f1b22fabd95
#  docker images
#  docker commit 3f1b22fabd95
#  docker images
#  docker tag 58f13433d17b test:demoimage
#  docker images
#  docker rm 58f13433d17b
#  docker ps -a
#  docker rm 64293aa5cc58
#  docker ps -a
#  docker ps -l
# docker run centos:centos7
========================================================================

Q:- Why we use custom Network Subnet for docker networking ?
Ans:- Docker container makes defaults subnet "172.17.0.0/16" for Networking. There may be many scenarios where we can not use default network due to some restrictions or in case subnet aleady use in network.

configure a custome network
=============================
# ip add show docker0
#  docker network ls
#  docker network inspect bridge
#  systemctl stop docker.service
#  systemctl status docker.service
#  ip link set dev docker0 down
#  ipp add show docker0
#  ip add show docker0
#  vim /etc/sysconfig/docker-network =========== And add this line "--bip=10.10.10.10/24"
#  systemctl start docker.service
#  ifconfig
#  ip addr show docker0
#  ip link set dev docker0 up
#  ip addr show docker0
#  brctl show
#  docker network inspect bridge
#  docker images
#  docker ps -a
#  docker run -it docker.io/centos /bin/bash
========================================================================
========================================================================
Docker Image
==============
Docker image can be descreibed as a template with all required configuration. whereas a container is a running instatnce of docker image, Like containers, image are not bound to the states i.e. image does not have states.

There are different images available from the OS/Application vendor along with the custom images from the community.

when working on container a DevOps/Application engineer generally create their own Docker image with all the customization, this enable them to launch a container quickly.

Methods for custom image creation
===================================
Interactive method:
=======================
In this way, you can download the base Docker OS image-> create container-> manually launch a shell->perform the customization-> commit the changes

This process will save your container to Docker image and that image can be stored/disributed

Automated method using Dockerfile
====================================
Dockerfile is text file with the directives/instructions for the image creation. "docker build" command is used to build the image which creates/configure the image automatically by reading the dockerfile. Dockerfile accept the information in the following format


DIRECTIVE              ARGUMENTS

Below are directives we are going to use to dockerfile

FROM:- This directive tell which base image to used to create the custome image, example centos,ubuntu,fedora etc.
RUN:-  This directive is use to define the command to be executed during the image build
ADD:-  This directive is use to define the files/directories to be copied from source to(local server) to the image during the image build
ENTYPOINT:- This directive defines container as executable
CMD:- This directive is use to define the arguments for the ENTYPOINT command
EXPOSE:- This directive defines the network ports on which container will listen

========================================================================
# mkdir -p /app/docker-image
# cd /app/docker-image
# vim Dockerfile

#use latest centos7 image
FROM centos:latest
#add the image maintainer name and email id
MAINTAINER pranchal  email pranchaldixit321@gmail.com
#update the centos image with latest available updates
RUN yum update -y
RUN yum clean all
#install network utilities, such as (ifconfig, netstat, etc)
RUN yum install net-tools -y
#install httpd web server
RUN yum install httpd -y
RUN yum clean all
#copy the index.html file from current directory to image's document root
ADD index.html /var/www/html
#define image to allow listen on port 80
EXPOSE 80
#define command to be excuted when container boots
ENTRYPOINT [ "/usr/sbin/httpd" ]
CMD [ "-D", "FOREGROUND" ]
========================================================================
# vim Dockerfile
Hello this is my first page
========================================================================
# docker build -t pranchal/apache-centos:latest .
#  docker images
#  docker run -it -d -P -h centos-apache f58bca361bb1
#  docker network inspect
#  docker network inspect bridge
#  curl 10.10.10.1:80
#  yum intall links
#  yum intall link
#  yum install link
#  yum install links
#  links 10.10.10.1:80
#  docker ps -a
#  docker exec dfb82490554f uname -a
#  docker exec dfb82490554f ps -eaf |grep httpd
#  ps -eaf |grep httpd
========================================================================

0 coment�rios:

Note: only a member of this blog may post a comment.