Tuesday, March 17, 2020

4. DOCKER & KUBERNETES : ImageCreate Way1 : Create Image using Container -> Push Image to Cloud/OnPrem

4. DOCKER & KUBERNETES : ImageCreate Way1 : Create Image using Container  -> Push Image to Cloud/OnPrem


########################## How to create an image in Docker machine from Container  ###################################
Step1: 1st Create Container
Step2: Create Image from Container using "commit"


Step1: 1st Create Container -------------------------------------------------------------
//1st Create a normal container "TestUbuntu" from image "ubuntu"
docker create -i -t --name TestUbuntu --restart=always ubuntu  //if image is not there it will pull automatically

docker system df

docker start TestUbuntu  //start container

docker ps -a

docker attach TestUbuntu  //go to parent process of container

hostname //to get container ID

cat /etc/hosts  //to get container ID with IP address

vi  //not there in container

--------------------------------------------------
// inside container
//on top of container we are installing vi module
apt-get -y install vim

mkdir cloud

cd cloud

vi testfile

This is test file
Esc :wq!

cat testfile
------------------------------------------------------
//to check layers in image, 1st we have to exit from container
exit

docker inspect ubuntu  (make sure u r in docker@default, it will show how many layers ubuntu has... )

Step2: Create Image from Container using "commit" -------------------------------------------------------------
//want to create template
//covert container to image, because only image can share
//custom image of ubuntu and share with every one to use
//we are building custom image
//all the data inside container will be converted to image (only volume will not be there inside container other than this every thing comes)
//container (internally its directory) => convert to image (file) with layers

//creating image "revisedubuntu" from contianer "TestUbuntu"
docker commit -a "DJ Created this image @ `date`" TestUbuntu revisedubuntu

docker images  //you see custom image created

docker inspect revisedubuntu  //we see number of layers as N + 1  (N from base image. 1 is our custom logic(folder,vi, testfile) )

//how to share created image outside docker machine
//we will push image to hub.docker cloud
//1st we will test the image the we will push
//pull the image, crate, start, attach (Every thing is REST sync call.. and need to to one by one its difficult so use Run which does all together for us)
//Run we use only for testing purpose.

docker images

docker run --rm -i -t revisedubuntu  (after run remove bez we dont need after testing)
ps ax

//check all are there or not,means cloud directory, testfile etc
cd cloud
ls

docker ps -a  //we dont see new container running because we used Run, which we use just for testing purpose after test automatically it will remove

##########################################################################################


#############now testing is done, now we will share to other users means SHARE IN CLOUD ##########################
1. We will see how to share on hub.docker Cloud
2. We will see how to share in Oracle Cloud
3. We will see how to share in OnPrem (Using TAR)


1. We will see how to share on hub.docker Cloud
################## In hub.docker how to Push ######################
1. IDENTITY
---------------
docker login
  pavankumarmadhu123
  Pavan_123h

//verify username and password is registered 

docker info  //we see username updated

docker images

docker tag revisedubuntu pavankumarmadhu123/revisedubuntu:1

docker images  //we can see image id is same for original and reference what we created

docker push pavankumarmadhu123/revisedubuntu:1

//go and verify in https://hub.docker.com check if repository creted or not

//to remove image
docker images
docker rmi -f e66   //it will untag the image, then it will remove the image
//-f is force, 1st go to child and then parent

//Test the image use Run
docker run -i -t pavankumarmadhu123/revisedubuntu:1   //locally not available bez its deleted, so it will download from cloud

ls
cd cloud
ls
vi
exit
docker ps -a   //created with wiered name bez we did not give name while testing.

2. We will see how to share in Oracle Cloud
################## In OCI how to Push ######################
//In OCI how to use
OCI:
  - docker login phx.ocir.io   (docker login <<region name>>.ocir.io)
  - username Tenancyname
  - Password
MFA:
    - Fingerprint
    - AuthToken
    - SSH API
  - docker push 

3. We will see how to share in OnPrem (Using TAR)
#################### onPrem SHARE ####################
//Now we will share onPrem - means no Cloud

//To share object, Serialize DIS to TAR

//in Docker Terminal

cd ~

mkdir tars1703

cd tars1703

docker images  //it will be slower bez Hyperv comes in to picture

docker save -o backpu.tar pavankumarmadhu123/revisedubuntu:1   //serialize and save

ls -ltr

docker images

docker rmi -f e66

docker load < backpu.tar  //convert from TAR to image
############################################################

3. DOCKER & KUBERNETES : BASIC DETAILS

3. DOCKER & KUBERNETES : BASIC DETAILS


################ EVERY DAY ACTIVITY ##############################
double click on "Docker Quickstart Terminal"
wait for sometime to generate IP address...

putty
192.168.99.100
username: docker
password: tcuser

open another terminal
Create duplicate session

username: docker
password: tcuser
sudo -i

docker info  //to check how many images and containers are there
ps ax | grep dockerd

docker system df  //to check number of images and containers and size accupaid
docker ps -a //to check image and containers status (wether exited or running etc)
###########################################################

############### PRUNE #####################################

//its like inspect command works for all objects, [image, container, volume, network etc..]

//remove unwanted container
docker container prune  //like GC, it will remove all stopped containers
//this is same as docker rm <<containerName>> but prune does for us

docker system df

//remove unwanted image
docker image prune  //like GC, but it wont remage dongling images
docker image prune -a  //will remove all images which does not contain container in it

docker network prune

docker volume prune  

//prune for all objects together
docker system prune

##########################################################################



2. DOCKER & KUBERNETES : INSTALLATION

2. DOCKER & KUBERNETES : INSTALLATION

https://drive.google.com/file/d/1eq5ZGs9JH9F7R1z3wtUcKIWJi8HFr7MM/view?usp=sharing





Docker & Kubernaties
----------------------------
LINUX FUNDAMENTALS


https://hub.docker.com/
------------------------
search for docker images

oraclelinux
Its free
In Tag : check size and version

oracle database
Its enterprice product
Its not free : it will ask for payment

oracle weblogic Server
Its not free : it will ask for payment

httpd
its free : no check out process

docker
click on explore
click - DOCKER CE

click - DOCKER EE
AWS
Azure

EE and CE difference is same as open jdk and oracle jdk
Eg:
Application performance
memory leakage support

########################################

for oracle employees/customers

container-registry.oracle.com
Sign in


Docker is Architecture
Kubernaties is a framework
##################################################################

Step6:
https://github.com  
                username : pavankumarmadhu123
                password : Pavan_123g
Step7:
https://hub.docker.com/
                username : pavankumarmadhu123
                password : Pavan_123d

------------------------------------------------------------
As per the diagram we will install one by one now:

VM with Linux - TCL (Tiny Core Linux)
Docker Installed (Docker CLI)
Network of Host - NAT (Communicating externally)
VM - IP (DHCP) - HOA
SSH Keys (RSA) (Internal)
from VM should 

Step8: Already we have laptop with Windows10

Step9: Oracle VM VirtualBox

Step10: 
docs.docker.com
 -> Search for "Docker Toolbox"
OR https://github.com/docker/toolbox/releases
 -> download - DockerToolbox-19.03.1.exe
 -> Install

################ EVERY DAY ACTIVITY ##############################
double click on "Docker Quickstart Terminal"
wait for sometime to generate IP address...

putty
192.168.99.100
username: docker
password: tcuser

open another terminal
Create duplicate session

username: docker
password: tcuser
sudo -i
###########################################################

docker prompt
------
docker info




##############################################

Docker Architecture

SWARM
Docker Host
Docker machine

####################################
//Search Docker Image
Go to -> hub.docker.com -> search for -> oraclelinux
OR
//Through docker command
docker search oraclelinux  (to search)

//Create Docker Image (below we are creating total 3 images - oraclelinux, httpd, ubuntu)
docker pull oraclelinux
docker pull httpd  (it will pull latest)
//pull particular version
docker pull ubuntu:20.04

//Verify ALL Docker Images
docker images

//Inspect Docker Image
docker inspect oraclelinux 
OR
docker inspect 0f4  (Using Image Id)
docker history oraclelinux  (how this image is built)

docker inspect httpd  (Inspect this image)

docker images

docker system df

##################################
//Create container of httpd and verify what happens to container
//container name can be upper or lower
//image name should be lower case

docker create --name TestApache httpd

//container is a docker process so we should be able to see
docker ps -a

//start the container
docker start TestApache

docker ps -a

docker top TestApache

ps ax | grep containerd

docker inspect TestApache  (it has lot of secured data we should not share to every one)

docker ps -a

ls /dev | grep tty

//go inside container and see what we can see this is just to verify..
docker exec -i -t TestApache bash  (i - interactive, -t - default terminal)
ps   //will not work bez we are in child process
curl //will not work bez we are in child process
docker stop TestApache

docker ps -a  //u see it as Exited

docker top TestApache //since container is not running so there is no containerd available

docker start TestApache

docker top TestApache  //now you will see containerd, bez above we have started the container, but will give different Id

docker images

//now we will create container for Docker Image - "oraclelinux"

docker create --name TestOL oraclelinux  //it will run for milisec and exit immediately, bez we have not used -i, -t to run in foreground

docker start TestOL

docker ps -a | grep TestOL  //we see as status as Exited, because its not running in foreground

docker rm TestOL  //physical remove, means remove file itself
docker kill <<ContinerName>>     //immediate kill

docker create -i -t --name TestOL oraclelinux  //you will see created Id, to run in foreground (when we use shell then we can use this command)

docker ps -a | grep TestOL

docker top TestOL  //to see containerd Id

docker ps -a

//go inside a container and check the IP address created for that container.
//exec will always create child process
docker exec TestOL cat /etc/hosts     //its not bash command so no need of -i -t, means only if its a bash then use -i -t to go inside container

docker exec TestOL -i -t TestOL bash //it will create one more child process and entered in to child

exit  //exiting from child process

//go to parent process
docker attach TestOL
ps ax

exit  //exiting from parent process

docker ps -a

docker create -i -t --restart=always --name TestOL2 oraclelinux  //create with restart policy, so that when ever exit from parent it should restart automatically

docker start TestOL2

docker attach TestOL2

exit  //exit from parent

docker ps -a | gerp TestOL2  //it will be still running...


exit
docker-machine stop default

1. DOCKER & KUBERNETES : INTRODUCTION

1. DOCKER & KUBERNETES : INTRODUCTION