Tuesday, February 1, 2022

Day1 - docker intro, Jenkins

Day1 - docker intro, Jenkins - Class Notes
1. Login to aws comsole
- select your region

Recap 
- understanding mavin
- Jenkins
- Jenkins agents
- Pipelines
- nexus repository (use to store artifacts)
 jar
war
zip
jekins
nexus
front end app
database
IIS
tomcat
nginx
apache
jetty
how you are going to launch?
- first you are going to create VMs(compute engine)
You are going to 
- install packages
- configure files
- start services
not only this, you are also going to much more such as,
- User/group cretion
- certificate and much more 
----------------------------
load balancer
 - Node Pools
Launch configuration (init scripts) -> Custom AMI(comes with all required packages)
- cloud watch (notification)
- scale in/ scale out

Install one VM 
- install all required software
- You can use podman to create image or use other tools.
=================
VM - using high memory/cpu
WHat is the cause?
You look for different aspect such as 
- AMI - Virtual machine architecture
Root cause
PM vs VM
physical vx virtual machiens
- Multiple OS
- Use only one - one at a time
- partition CPU/Memory
We want to use multiple machines simultaneously. how?
- Front end as well as backends.
- We want to partition same machine half and half for backend and front end.
Instead of physically divinding memory, we want to divide virtually. 
This concept is called virtualization.
Virtualization is the process of running multiple virtual systems or resources on top of a sysge physical machine. These resources could be a storage device, network or even an operating system.
-> app
-> Virtual Machine [ VMs (Guest OS)]
-> Hypervisor
-> physical
Problem with VM?
- Platform specific (windows or linux)
- resources utilization if not good
- In a system physical system, you have systema and systemb and you have two application running but cpu/mem used is only 20%.

There are three components.
google : vm architecture
Host OS
Hypervisor
Guest OS
Bin/Libs
Application

There is a concept of havy weight to light weight. What is taking heavy weight out of these component.
Here, guest OS is taking tool..
physical memory is a problem, 



what is the solution?
virtualization on OS..
- it will become light weight
it will only contains
- lib/lib
- application
container technology/containerization
OS level virtualization
- light weight
- Dynamic memory allocation
app1   | app2     | app3 ..
Bin/libx  | Bin/libs | Bin/Libs
Container engine
Operating system
Hardware

now, it became light weight. we can create image of the instance.
This image is going to be
- Dynamic memory
- Faster bootup = with in sec
- Simple network to communication
in sinlr host, you can create multiple conatiner.
using these options, you can isolate software isolation.
You have Dev/Test/PreProd/Prod env as well.
Environmental differences
- Traditionally, we may have different image but now, you will use same image that is created using the instance in.

Note: Once you create image, you can not change the software.
- Isolation 
- One image for all env
Container engine
- Docker engine
- CRI-O
- RKT
- Containerd
- PODman (utility)

google docker architecture 
docker.com/get-started ..
Three components
- Docker clients (utility command) - provide instruction - build image, install
- Sends instruction to engine
- Docker engine
- Docker Registry (Storage for image)
Docker runs on client / server architecture.
Docker client/server communicate using rest aAPI

VM
 - Docker package (client+engine)
Rest api (its like http server.)
- when you run make change on code at github, jenkins running the job. 
client connects to rest api (docker daemon) for connunication or to send instruction.

=======================
ssh <instanceIP>
# docker
no command found
# systemct status docker
# apt install docker.io
This package is not available on index list
# apt update
# apt install docker.io
# docker
Repo list location
# /etc/apt/sources.list.d; ls
---------------------
apt-get update
apt-get install jenkins
---------------------
# systemctl status docker
active/running
docker application container engine

# docker
show you help
go under commands
start/stop/pull/push/kill/inspect ..

How to use container? 
There are two ways, you can use
1. As a job - just run one time (execute a single script, see result and exit)
2. As a service - Running 24/7, all the time. 

in a linux point of view,
VM
 - hello.sh
$ sh hello.sh
$ sh hello.py
$ java welcome
you will get output. but you need depeldencies.
Lets see how to use docker as a "job" point of view.
you don't need dependencies since container contains all required packages (but you have to have it right? - lol)

Registry
- docker HUB
hub.docker.com (like git hub for images)
search windows, centos ...
search for ubuntu and see how to install
# docker 
images, ps, pull, run
# docker pull ubuntu
# docker pull ceontos
$ docker images
# docker run --help
see the usage : docker run [options] IMAGE [COMMAND] [ARG...]
-d , -t, -u, 
# docker run -i -t ubuntu pwd 
-i -> interactive
-t -> image
ubuntu -> image name
pwd -> command
# docker ps # no output
# docker ps -a # show all container
it takes couple of seconds to start container. 
# docker run -it ubuntu ls -ltr
you got the output at a single time.
How to run multiple commands
# docker run -it ubuntu bash
# you are connected to container
# ls -l; pwd
# docker 
no command found becuase you are inside container and docker is not installed.
We are on foreground mode and running command inside the container
# exit
# docker ps
# docker ps -a 
you will see the output now.
The container is executed once the job is completed.
but we can run docker in deatch mode.
# docker run -it -d ubuntu
# docker ps
# docker run
# docker --help
review the -d help option
3 ways to run command on docker
-------------------------------
1. run a command 
# docker run -it ubuntu pwd
2. Run multiple commands
# docker run -it ubuntu bash
3. Run in detach mode
# dicker run -itd ubuntu

see the option exec - run a command in a running container
you can execute on ecommand
# docker ps
# docker exec -it <container ID> pwd
create a direcoty on container, and lets install software
# mkdir app; cd app
# touch welcome.sh
# apt install vi -y
# apt update
# vi welcome.sh
echo "Hello world"
Note: Linux container can run on linux and windows but windows container only runs on windows (I am  not sure about it)
# chmod 755 welcome.sh
# ./welcome.sh
Hello world 
# exit
Run the command on docker from host
# docker exec -it <container_ID> sh /app/welcome.sh
# docker exec -it c442bhc54eee sh /app/welcome.sh

# docker ps
review commit option
# docker commit --help
docker commit [OPTIONS] CONTAINER {REPO[:TAG]]
# docker commit <container ID> welcome:latest # we are creating image name: welcome
latest is the version or you can state v01
# docker images
It created your own image..
see the size..
compare the original size and the one you created, you will see different size because its your custom image.
# docker images
# docker ps
# docket stop <container id>
# docker rm <container id>
# docker ps -a
now, its gone..
Now, try it,
# docker run --name=eg1 welcome sh /opt/welcpme.sh
eg1 is the name of your container.
you will see the output
- you can customize it and use as an image.
- whatever you made changes, you can create image and save for later use. You can keep this image wherever you want.

docker hub allow you to store the image. You can sign up for free.
once login, click on repository
create repolitory
name: welcomeimage
private/public and click on create
you just created a repo on docker hub.

Now, look at the option tag
create a tag TARGET_IMAGE that referes to SOURCE_IMAGE
how to rename?
there is certain format image need to be on
such as user/image_name
# docker tag welcome devopsjuly22017/welcomimg:latest
# docker images
How t push it..
# docker push devopsjuly22017/welcomeimg:latest
denied, access denied
you have to login
# docker login
login with docker id
username: devopsjuly22017
passwd: ******
Login succeeded
# docker push devops/welcomeimg:latest
it is pushing
go to hub.docker.com and verify the image is uploaded.

# docker ps
# docker images
# docker ps -a
# docker rm ex1
# docker rmi welcome # use rmi to remove image
# docker rim <image_ID>
# docker images
Now, image is deleted.
Now, lets go ahead and pull it.
get the link from hub.docker.com
# docker run devopsjuly/welcomeimg sh /api/welcome
your image is downloaded as well you get the output.
Next session:
as of now, we executed some commands, next we will bind with port number.
we will discuss about
- service
- network
- volume
- dockerfile
- docker-compise
Assignment:
Create an image from running container, push the image to aws ecr repo.
Hint: aws console - search ecr -> elastic container registry
- create a repository
- get started
and follow the steps

No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...