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
############################################################

No comments:

Post a Comment