Docker
1. What is required to host an application?
·
Use ---------- (to deploy the application)
·
Process ----- (We are going to create a process,
The process will maintained our application up and running)
·
Storage
·
Network----- (For manage our application
traffic)
·
.
·
O.S
·
To host an application we need a hardware
(Physical Machine).
Need to insert Image (Traditional Method)
·
Using Hypervisors Software’s we are
virtualization Physical machines into a virtual machines.
·
(VM Ware, Oracle Virtual Box, Citrix Xen etc.,)
·
So we can able to create a virtual machines
based on Physical machine capacity.
·
Each virtual machine will have its own OS.
·
With help of virtual machines we can utilize
maximize our hardware utilizations.
·
In each Operating System we have a guest
Operating System.
Types of Hypervisors:
1.
Bare Metal Hypervisors / Native Hypervisors (VM
Ware, ESX/ESxi, Citrix Xen) ------------(AWS is using Citrix Xen)
a.
No need to create Operating for type 1
Hypervisors.
b.
Without Operating system we can able to create a
type 1 Hypervisors.
c.
For type 1 Hypervisors no need Operating System.
2.
Oracle Virtual Box, VM Ware Workstation, Hyper-V ----------------(Only for local (Personal
Laptop))
a.
It’s a Software Hypervisors.
Nee to insert Image (Hypervisors Software)
1. What is the problem we have
with traditional approach?
·
Installation & Configuration.
·
Time consuming.
·
Need to perform Install/Configure across all
servers like DEV, QA, and PROD.
·
We may end up with inconsistency (compatibility).
·
.
·
Virtual machines are heavy weight.
·
Virtual machines takes lot of CPU & Memory.
·
Because of Each and every Virtual machines we
have an O.S (We call it as Guest Operating System).
·
For this reason Containerizations came in to the
market.
1. What is the difference between
Virtual Machine & Containers? (Interview
Question)
=======================================================================================================
What is Container?
·
Container contains everything which is required
to run application (Software) like application code & It’s dependencies (Software + libraries) Configurations, Env
etc.,
·
Container will carry our applications and its
dependencies.
·
Containers are light weight, because containers
will not have an Operating System. (Full glone O.S)
·
Using Containerizations we can isolate the
application in O.S Level.
o
If containers
will doesn’t have Operating System, then how it will work? (What is
the common for all containers).
o
Host O.S Kernel
§
The Kernel is interface between Software and
Hardware.
§
The kernel is going to convert the code into
human readable to machine readable code.
§
The kernel is responsible for communicating
between hardware and software.
§
O.S is nothing but kernel.
§
Isolation happening at O.S Level / Software
Level.
o
Where you have a containerization Runtime
o
Kernel is heart of our O.S
·
Container can be created in virtual machines and
physical machines also.
·
If containers are work in one environment it
should work in all environment.
·
Containers are portable.
·
Container is nothing but runtime instance.
Containerizations:
·
Using containerization we can build & ship
& run application as a container.
·
We can containerized our deployment application
(in simple words).
Containerizations Platforms /
Software’s:
·
Docker
·
Rocket (RKT)
·
Podman
(By RedHat)
·
Container-D
·
CRI-O
o
Isolation at Software Level (O.S Level)
·
Docker is most popular.
·
Docker has very good CLI & API’s to manage
containers/Images.
·
Docker is
open source.
What is Docker?
·
Docker is a containerization platform (Software)
using docker we can build, Move (ship) and run application as containers.
Benefits of Docker
Ø
Portable
Ø
Cost Saving
Ø
Scalable
Ø
Quick start and stop
Ø
Quick to deploy
Ø
Light weight
Ø
Easy to Monitor
Ø
Secure
Docker Architecture:
·
Docker consists of three Major components.
1.
Docker Client
2.
Docker Demon
3.
Docker Registry
Docker Image:
·
Docker image is lightweight,
·
Stand-alone
·
Executable package that includes everything
needed to run a piece of software,
·
Including the code, a runtime, libraries,
environment variable and config files.
Docker File:
Ø
Docker file is a file,
Ø
It will describe the steps in order to create an
image quickly.
Ø
The docker demon runs the instructions in the
Docker file are processed from the top down, so you should order them
accordingly.
Ø
The Docker file is source code of Docker image.
Docker installation:
Ubuntu 20.04 LTS
Ø
sudo apt-get update
Ø
sudo apt-get install docker.io
Ø
sudo curl –fsSL get.docker.com | /bin/bash
o
sudo apt update –y
o
docker version
--(display client information)
§
After check version we getting an error like
“Permission denied”
§
Docker is installed
§
Docker process started (or) not? ------Docker
demon is started?
·
ps -ef | grep "docker"
·
sudo service docker status------Active
o
As a normal user we don’t have permission to run
the docker demon
o
Sudo docker version (display client info &
Server info)
§
When we installed docker in the backend default
group created
§
The group name called “docker”
·
Add the normal user to “docker group”
·
Sudo usermod –aG docker $USER
·
Sudo usermod –aG docker Ubuntu
o
Exit
======================================================================================================
Video 03
Software + Library + Configurations
Create Registry in hub.
Docker:
Ø
Registry Name: ramadevi2023
Ø
Password: Ramadevi@09
Home directory of docker?
·
/var/lib/docker /
·
docker info
·
Sudo ls /var/lib/docker/
ls-lar
Docker
commands:
·
Docker
build -t <Registry/Repository> :< Tag> . (.
Current directory/ Build context)
·
Docker
build –t <Image Tag> <build Context>
o
Build
Context:
o
From
which directory (Folder) we are building an iamge.
·
Docker
build –t ramadeiv2023/maven-web-application:1 .
·
Docker
images -------------------------------------- Images from local repo.
·
Docker
push <Registry/Repository> :< Tag>
o
After push the image into Repository you will
get an error “requested access to the resource
is denied”
§ Docker login -u <User Name> -p
<password> <Registry URL> ----------For private registry
§
Docker login -u <User Name> -p
<password> 10.12.13.14:8081
§
Docker login -u <User Name> -p
<password>
§
Docker login -u <User Name>
·
Docker
run –name <Container Name> <Image>
·
Docker
run –name mavenwebapp –d –p 8080:8080
<Registry/Repository>:< Tag>
·
docker run --name mavne-web-app -d -p 8080:8080
ramadevi2023/maven-web-application:1
o
–p =
Port publish/ port Mapping / Port
Forwarding
o
Ipaddress:8080/maven-web-application
·
-p
<Host port: Container Port>
·
Host
Port: Any port which is available in the host.
§
With –p option we can access outside of docker.
§
Host port should be unique.
§
Container name & Host port should be unique.
§
Not mandatary to do port mapping for containers.
We can create a containers without port forward.
o
–d = Detached Mode (Background Mode) -----Interactive
session in background
o
–name = Name of the container (We can provide custom name)
§
If you don’t mention –name docker will give by
some random name.
§
Try to run without –
d Option
§
Container name can’t be same.
§
Each Container will have one IP Address
(Container IP Address).
§
Each container will communicate app context (125.25.26.11:8080/AppContext).
·
Docker
pull Registry/Repository>:<Tag>
======================================================================================================
Video 04
NodeJS Application: (NodeJS-app-mss)
Docker run –name nodeappjs –d –p 3000:9981 <Registry/Repository>:<
Tag>
http://localhost:9981/mithuntechnologies
·
curl - v ContainerIP:9981/
·
curl
- v ContainerIP:9981/ mithuntechnologies
·
curl - v ContainerIP:9981/html
·
curl - v ContainerIP:9981/jsonData
Run=pulling + Creating + Starting
Image
Commands:
·
Docker build –t
<Image Tag> <build Context>
o
Image Tag = <Registry / Repo: Tag>
§
Docker build –t ramadevi2023/mavn-web-applicatoin:1
.
·
ACR
·
GCR
·
DTR (Docker Trusted Registry)
·
JFroG
·
ECR
o
Elastic Container Registry
o
It’s a fully managed docker container registry.
·
Nexus
o
Docker build –t nexus.tcs.com/ mavn-web-applicatoin:1
.
o
Docker build –t 172.0.12.2:8081/ mavn-web-applicatoin:1
.
List
Images:
·
Docker images / docker image ls -------------- Images list locally
·
.
·
Docker info ----------------------------------------
Information about server
·
.
·
Docker inspect
<Image Id /
Name>---------------- More details
about image / More details about container
·
Docker image inspect <Image Id / Name>---------------- More details about image / More details about
container
Push
Images:
·
Docker push <Image Tag>
Authentication
with docker registry:
·
Docker login - - username <User name> -p
<Password> <Registry End Point / URL>
·
Docker login
- u <User name> -p
<Password> <Registry End Point / URL>
o
Docker = docker login –u ramadevi2023 -
p Ramadevi@09
o
ECR = docker login – u aws - p Password
(ecr url)
o
JFroG = docker login –u admin - p Password 172.0.12.2:8081 .
Container
Commands:
·
Docker ps
--------------- To display the container list
·
Docker inspect <Container ID / Container
Name>------------------ To see more details about the container
======================================================================================================
Video 05 & 06
Delete image:
·
Docker rmi <Image Tag / ID>
·
Docker rmi <Image Tag / ID> , <Image
Tag / ID> , <Image Tag / ID>
·
Docker rmi $(docker image-q)
---------------------------------------------------------------------Delete all
images
·
Docker rmi - f $(docker image-q)
1. Can we delete image if there
is a container created/ running out of that image?
·
NO
2. How we see/list the layers of
specific image?
·
Docker history <Image ID/ Tag>
3. What is dangling Image?
·
A dangling image is an image, without any
repository reference (tag).
4. How to display only dangling
images?
·
Docker rmi
- f <Image tag>
·
Image is not yet deleted, it is untagged.
·
It has remove the repository reference.
·
Docker images
- f dangling=true
·
|
·
|
·
F = Filter
5. How to re-tag the dangling
images?
·
Docker tag <image ID> <New Repo Details>:1
Delete dangling images:
Docker rmi $ (docker
images – q - f dangling= true) (Disk
full = No space left on
the device)
·
Docker system prune
o
All stopped containers
o
All network not used by at least one container
o
All dangling images
o
All dangling build cache
·
Docker image prune
o
This will remove all dangling images
·
Docker container prune
o
This will remove all stopped containers.
·
Docker network prune
o
Remove all custom network not used by at least
one container.
·
Docker volume prune * * * * *
o
Remove
all local volumes not used by at least one container.
o
Once we delete the volume we can’t able to
recovery the data/Volume.
Docker tag * * * * *
·
Same image we can tag with multiple repository.
o
Docker tag <image ID> <New Repo Details>:1
o
Docker build – t ramadevi2023/maven-web-app:1 .
§
We can tag one image with multiple registry
(docker, ECR, Nexus)
|
Docker load – I <Filename>.tar I = in put |
|
Docker save <Image ID / Tag> - o
<Filename>.tar 0 = out put |
|
SCP |
·
Docker save ramadevi2023/maven-web-app:1 - o
MavenImage.tar
·
Docker load
- i MavenImage.tar
Docker file: It’s a text file,
it contains instructions to create a docker image.
Image: Package, It contains all the
requires software + Dependencies + Env + Configuration file.
Container: Run time process of docker image.
Container
Commands:
Running
Containers:
Ø Docker
ps ---------------------------Docker process
Ø Docker
container ls
All
Containers (Running + Stopped):
·
Docker ps – a
·
Docker ps - -all
·
Docker container ls – a
·
Docker container ls - - all
·
.
·
Docker ps –aq
Create
containers:
Ø Docker
create - - name <Container name> - p <Host port: Container Port>
<Image>
Ø Docker
run - - name <Container name>
- p <Host port: Container Port> <Image>
o Docker Create
§
It will just create a container, not start the
container.
o Docker run
§
It will create container and it will start
container.
§
Create + Start
o
Docker start
<Container ID / Name>
o
Docker stop
<Container ID / Name>
o
Docker restart <Container ID / Name>
§
Stop and start the container
Delete
container:
·
Docker rm <Container ID / Name>
·
Docker rm
- f <Container ID / Name>
·
Docker rm
- f <Container ID / Name> <Container ID / Name>
<Container ID / Name>
·
Docker rm
- f $ (docker ps -aq)
-------------------------------------------------------------------------------It
will delete all containers
·
Docker container prune-----------------------------------------------------------------------------------------Delete
only stopped containers
·
Docker rm
- f $ (Docker ps -aq –f status=exited)
o
Docker container ls –aq –f status=exited------------------------------------------------------------Display
only stopped containers.
o
Docker containers ls - aq
-------------------------------------------------------------------------------Display
only containers id’s
1.
What is the difference between docker stop and docker kill? * * * * *
·
Docker stop
o
Docker stop <Container ID / Name>
o
It is going to gracefully stop the
process.
o
It will issue (Send) SIGTERM signal to
the main process inside the container.
·
Docker kill
o
Docker kill <Container ID / Name>
o It
is going to forcefully kill the process.
o It
will issue (Send) SIGKILL signal to the main process inside the
container.
1. Can
we have more than one process running inside a container? * * * * *
·
Yes
·
Technically it’s possible.
·
But it’s not recommended.
o
Isolation
·
Docker pause <Container ID / Name>
---------------------------------Sleep mode/ pause the process.
·
Docker Unpause <Container ID / Name>------------------------------
·
.
·
Docker top <Container ID / Name>
-------------------------------------it will show the process inside the
container / if you want to see what process is running inside the container.
·
.
·
.
·
Within Docker (Inside the node)
·
Within the docker we can check process is
running or not
o
Docker inspect <Container ID / Name>
§
Copy the container IP Address
§
Curl –v
IPAddress:8080/java-web-app/
·
Outside Docker
o
IPAddress:Hostport/AppContext
·
Intentionally you stop the container
o Docker stop <Container ID / Name>
o
Then check whether process running or not inside the docker and outside
the docker
o
Using
o
Docker pause command also you can check once.
o
And see the difference.
1. How
to trouble shoot if your application is not accessible and that application is
running as a container? * * * * *
1. Server
should be up and running and within the server docker demon (docker process)
also up and running.
o
Ps –ef | grep “dockerd”
o
Sudo service docker status--------------Should
be in active status
2. Check
if container is running or not.
o
Docker ps
o
Docker container ls
3. Check
if your application able to access or not locally.
o
If you
server part of private network your system also part that same network (Private
network).
o
If you part of the same network work then you
can able to access the process.
§
Check curl – v telnet://AWSIP:7070 (Host port)
§
.
§
Check locally (inside the docker) whether access
or not
§
sudo apt install net-tools
§
sudo Netstat -tunlap
·
Curl – v localhost:7070/java-web-app/
·
If working in locally and not working not able
to access in different machine means it might be networking problem.
·
If not working in locally
·
We can go inside the container and check the
status of that container.
How to
execute the commands on the Containers:
·
Docker exec <Container ID / Name> <Command>
·
Docker exec <Container ID / Name> ls
·
Docker exec <Container ID / Name> pwd
·
Docker exec <Container ID / Name> ps –ef
o
Docker exec javawebapp ls
o
Docker exec javawebapp ls webapps
o
Docker exec javawebapp netstat –tunlap
o
Docker exec javawebapp ps -ef
Get
inside the container Shell:
·
Docker exec –it
<Container ID / Name > /bin/bash
·
Docker exec –it
<Container ID / Name > bash
·
|
·
|
·
Interactive
terminal
o
After using above command we jumped in to inside
the container shell or bash.
o
Ls
o
Curl – v localhost:8080/java-web-app/
o
Ps –ef
§
Service tomcat status
§
Apt install net-tools –y --(For trouble shoot)
(netstat
-tunlp)
§
Apt update –y ------------(For trouble shoot)
Docker logs
o
It will display whatever has been sent to STDOUT
& STDERROR by the process which is running inside a container.
o
It will print the logs of the containers.
·
Docker logs <Container ID / Name>
·
Docker logs - - tail 10 <Container ID / Name>
·
Docker logs
- f <Container ID / Name>
·
|
·
|
·
Floating logs
/ Keep appending the live logs
·
Docker stats <Container ID / Name>
----------------------------Display Static of that container. --------Display
CPU/Memory/ Network Input/output of that container.
Set limit CPU and Memory while create a
container?
·
1 core CPU = 1000m
·
0.5 core CPU = 500m
·
0.25 core CPU = 250m
o
256Mi = Mega bites
o
1Gi = Giga bites
o
2Gi = Giga bites
o
4Gi = Giga bites
§
Memory allocation for new containers not for
existing containers.
§
·
Docker run –d - - name <Container Name> - p <Host port :
Container Port> - -
cpus “0.25” - - memory “256Mi” <Image>
·
Docker run –d - - name <Container Name> - p <Host port :
Container Port> - - c“0.5”
- - memory “1Gi” <Image>
·
Docker run –d - - name <Container Name> - p <Host port :
Container Port> - -
cpus “1000m” - - memory “2Gi” <Image>
o
If application run out of CPU
o
Your application will hung (Very slow response).
§
If application run out of Memory (O O M)
§
Application will be stopped / terminated.
Rename
Container:
Docker rename <Container ID /
Old Name> <New Name>
Docker cp <Source>
<Destination>
What is
docker commit?
How to
container changes as an image?
·
Docker commit
·
Docker commit <Container Id / name>
<Image Tag>
Docker ps – a | awk ‘$2=” Hello-world”
{print $1}’ | xargs docker rm ---------------------It will delete all the
containers related Hello-world Image
Docker search <Image
name>------------------------------------------------------------------Search
images form the remote repo (hub.docker, nexus)
======================================================================================================
Video 07
FROM
·
FROM is used to get (Pull) the base image
to create your own image.
·
Our image will be created on top that base
image.
o FROM
<Image>
o FROM
tomcat:8.2
o | |
o | Tag
o Repo
§ FROM
Nexus.IBM.com/Openjdk:8.0
§ FROM
172.15.2.0/Openjdk:8.0
·
Can we have any other
instructions other than FROM as first instruction in Dockerfile?
o ARG
Instruction as first instruction in Dockerfile.
o .
·
Default Dockerfile
name?
o
Dockerfile
o .
·
Can we change the
custom name for Dockerfile?
o docker
build –t <Image Name> - f <Custom
Dockerfile Name> <Build Context>
o |
o File
name
MAINTAINER
·
We can define the author / Owner / Maintainer of
the image.
·
It’s kind of document purpose.
o
MAINTAINER <Name><Email-id>
o
MAINTAINER
Ramadevi ramadevi@gmai.com
COPY
·
It will copy files / folders from
build context (From host
server where you are building image) to the Image.
o
COPY <Source> <Destination>
o
COPY . .
o
COPY target/maven-web-application
.war
/usr/bin/tomcat/webapps/maven-web-application .war
o
§
Source -------------
Files or folders path from the build context.
§
Destination -------
With in the image, in which directory you want to copy.
ADD
Ø
ADD also can be to add (COPY) files/folders to
the image.
Ø
ADD can add (COPY) local files/ folders (build
context) and also files form remote (https endpoints) locations.
Ø
If we are adding tar file using ADD.
Ø
It will add (copy) to the image and also it will
extract that tar file in that image.
o ADD
<Source Path> <Destination Path>
o ADD target/maven-web-application
.war
/usr/bin/tomcat/webapps/maven-web-application .war
o .
§ ADD
<Source End Point> <Destination End Point>
§ ADD
https://Url.tar
/opt
1. What is the difference between COPY and
ADD?
·
COPY
o
COPY we can copy the files/ folders form build
context.
·
ADD
o
ADD can also copy files / folders form build
context and remote locations.
o
If we are adding tar file using ADD.
o
It will add (copy) to the image and also it will
extract that tar file in that image.
======================================================================================================
Video 08
We
can run (execute) some commands/ scripts using RUN,
CMD, and ENTRYPOINT. * * * * *
RUN
Ø
We can run (execute) some commands/Scripts using
RUN.
Ø
These RUN instructions will be executed
(Processed) while creating (Building) an image.
Ø
These instructions will be processed on top of the
previous layers.
Ø
We can have no number of in a Dockerfile.
Ø
The Docker Demon will process all RUN
instructions one after the other from top to bottom.
Ø
With help of RUN we can do some configuration
and install the software’s.
o
RUN <Command> <arg…1>
<arg…2> <arg…3>
o
RUN <Command> <arg…1>
<arg…2>
o
.
o
RUN apt install git –y
o
RUN mkdir –p /opt/app
1. What is the difference between
RUN & docker run?
CMD
·
We can run (execute) some commands /Scripts
using CMD.
·
These CMD instruction will be executed
(Processed) while starting the container.
·
Using CMD we can start the process inside the
container.
1. Can we have more than one CMD
in Dockerfile?
·
Technically………. yes.
·
It’s possible to have more than one CMD.
·
But Docker will not execute all the CMD even
though you have more than one CMD.
·
Docker will execute the recent/last one in the
order.
·
Docker run –d
- - name CentOS_Container Centos
o
Docker ps
(status is Exited) -----------------------------------------------------------Nothing
we installed in centos due to that reason it is Exited, this just a bash
command.
o
Docker start <Container Name/ iD>
·
Docker run - it -
- name CentOS_Container Centos /bin/bash ---------------------------container
will run in interactive mode, we get in to the inside of the container.
·
Ps –ef
·
Java
·
.
·
.
o
Let’s create dummy image inside the container
§
Mkdir Docker_File_Labs
·
FROM Centos
/ Centos:centos8 / Ubuntu
·
RUN echo “Welcome RUN ONE”
·
RUN yum install git curl wget –y
·
RUN mkdir – p /opt/app
·
RUN echo “Welcome RUN Two”
o
Docker build – t imageone.
·
FROM Ubuntu
·
RUN echo “Welcome RUN ONE”
·
RUN apt update - y && apt install Openjdk:8 git curl wget –y
·
RUN mkdir – p /opt/app
·
RUN echo “Welcome RUN Two”
·
CMD [“date”]
·
CMD [“git”,”- - version”]
·
CMD [“java”,”- - version”]
·
CMD [“echo”, “Welcome from CMD”]
·
RUN echo “Welcome RUN Three”
·
CMD [“date”]
1. What is build cache in build docker?
·
If that image layer is already processed.
·
And there is no changes on that layers.
·
It is going to use that layers.
·
This is called Cache.
o
It will improve the speed of building the
images.
o
No need to create the layers if no changes in
Dockerfile.
·
No Cache:
o Docker
build it <Image-Name> - - no –cache .
·
Image layers:
o Docker
history <Repository>
ENTRYPOINT:
·
We can set ENTTYPOINT (Command / Script) for
your container.
·
This ENTRYPOINT also will be executed
(Processed) while starting the container.
·
FROM Ubuntu
·
RUN echo “Welcome RUN ONE”
·
RUN apt update - y && apt install
Openjdk:8 Git curl wget –y
·
RUN mkdir – p /opt/app
·
RUN echo “Welcome RUN Two”
·
ENTRYPOINT [“echo”,” Welcome from ENTRYPOINT”]
o
Docker build - t <Repo/Regi> - f
Dockerfile_ENT .
1. What is the difference between CMD & ENTRYPOINT?
·
CMD
o CMD
can be overridden at run time (While creating a container we can
overridden).
o CMD
[“echo”,” Welcome from CMD”]
o .
o docker
run <Image> <Command>
o docker
run Imageone date
§ Docker
run imageone
§ Docker
run imageone pwd
§ Docker
run imageone ls /
·
ENTRYPOINT
o ENTRYPOINT
Can’t be overridden.
o The
command it will consider as an argument.
1. Can we have a
CMD & ENTRYPOINT together in a Dockerfile?
·
FROM Ubuntu
·
RUN echo “Welcome RUN ONE”
·
RUN apt update - y && apt install
Openjdk:8 Git curl wget –y
·
RUN mkdir – p /opt/app
·
RUN echo “Welcome RUN Two”
·
ENTRYPOINT [“echo”,” Welcome from ENTRYPOINT”]
·
CMD [“ls”,”/”]
o Docker
build - t image3 - f Dockerfile_ENTCMD.
o Docker
run image3
§ The
command it will consider as an argument for your ENTRYPOINT.
1. While starting the container always I want to execute
same command/ Script but I should have an option to pass different parameters
(ARG) at run time?
·
ENTRYPOINT [“sh”,”test.sh”]
·
CMD [“start”]
o sh
test.sh start
o .
o Docker
run <Image> status
o Docker
run <Image> restart
o Docker
run <Image> stop
RUN, CMD & ENTRYPOINT can be define in 2 forms.
·
Shell form
·
In shell form your command will be executed as
below in internally.
·
.
·
/bin/bash
-c mkdir – p /opt/app -----------------RUN
·
/bin/bash
-c java –jar app.jar ----------------- CMD
·
/bin/bash
-c sh catalina.sh -----------------ENTRYPOINT
·
.
o
RUN <Command> <arg…1>
<arg…2> <arg…3>
o RUN
<Command> <arg…1> <arg…2>
o RUN
<Command> <arg…1>
o .
o RUN
mkdir – p /opt/app
o RUN
apt install wget – y
o
§
CMD <Command> <arg…1>
<arg…2> <arg…3>
§ CMD
<Command> <arg…1> <arg…2>
§ CMD
<Command> <arg…1>
§ .
§ CMD
sh catalina.sh
§ CMD
java –jar app.jar
§
·
ENTRYPOINT <Command> <arg…1>
<arg…2> <arg…3>
·
ENTRYPOINT <Command> <arg…1>
<arg…2>
·
ENTRYPOINT <Command> <arg…1>
·
.
·
ENTRYPOINT sh catalina.sh
·
ENTRYPOINT java –jar app.jar
·
Executable From
·
In Executable form your command will be executed
as below in internally.
·
.
·
/bin/<executable (Command)> <arg1> <arg2>
·
/bin/mkdir
/opt/app -----------------RUN
·
/bin/ sh catalin.sh
----------------------CMD
·
/bin/node app.js -----------------------CMD
·
/bin/java
- jar app.jar -----------------ENTRYPOINT
·
.
ü RUN
[“executable (Command)”,”arg1”,”arg2”]
ü RUN
[“mkdir”,”- p ”,”/opt/app”]
o CMD
[“executable (Command)”,”arg1”,”arg2”]
o CMD
[“sh”,”catalin.sh”]
o CMD
[“java”,”- jar”,”app.jar”]
§ ENTRYPOINT
[“executable (Command)”,”arg1”,”arg2”]
§ ENTRYPOINT
[“sh”,”catalin.sh”]
§ ENTRYPOINT
[“java”,”- jar”,”app.jar”]
CMD & ENTRYPOINT is recommended to define in executable
form.
Because of the container process as started as a root
process.
If anything happened to the container it will come to know,
because of it’s not working as a child process.
======================================================================================================
Video 09
ENV
ü
We can set environment variable.
ü
Whatever ENV we have set in Dockerfile using
ENV, these ENV can be referred / used with in the Dockerfile instructions.
ü
(or) Within your container any process (Code)
can access.
ü
Docker inspect <Image>
o
What has be defined in ENV, where ever I create
a container, I can able to access those variables (With in the container).
o
Docker exec – it <container iD / Name>
bash
o
Env
§ How to refer ENV in Shell Script?
§ $HOME
§ &JAVA_VERSION
§ $PATH
o
ENV <Key> <Value>
ü Can we set environment variable while creating a container?
o
Yes
o
Docker run
- d - - name <Container Name> - e <Key>=<Value>
<Image>
o
Docker run
- d - - name <Container Name> - - env <Key>=<Value>
<Image>
ARG
ü
We can define arguments (Kind of a Variables) in
a Dockerfile using ARG.
ü
We can access ARG with in Dockerfile while
building an image.
ü
.
ü
ARG we cannot able to access in container.
o What
is the use of this ARG?
o
Instated of hardcode something in Dockerfile, we
will able to parameterize Docker build using ARG.
o
Pass some values building an image.
·
ARG baseImageTag=latest
·
FROM Ubuntu: baseImageTag
·
RUN echo “Welcome RUN ONE”
·
RUN apt update - y && apt install
Openjdk:8 Git curl wget –y
·
ARG
PROJECT_HOME /opt/app
ü
RUN mkdir – p $PROJECT_ S
·
HOME
·
ARG $filename /opt/app/app.text
·
RUN echo “Welcome RUN Two”
·
ENTRYPOINT [“echo”,” Welcome from ENTRYPOINT”]
ü
Docker build - t Imageone - - build – org
baseImageTag=21.10 - - build – org filename=xyz.text.
1. What is the difference between ARG & ENV?
LABEL
ü
Labels are kind of a Metadata (data about data).
ü
.
ü
Labels are key value pairs.
ü
We can add labels to your image.
o
LABEL <Key> <Value>
WORKINGDIR
ü
We can set working directory for our image/
container.
o
Docker exec - it <Container ID / Name> pwd
o
Docker exec - it <Container ID / Name>
bash
======================================================================================================
Video 10 Troubleshoot
USER
ü
We can create the user & we can set the USER
for the image/ container.
ü
So that process will started as that user.
ü
USER should be part of that image.
o By default which user will process commands in image/
container?
o Root
user of the container.
§ How to
create a USER?
§
EXPOSE
ü
This is purely for a documentation purpose.
ü .
ü If
you don’t know on which port opened for this container.
o
Docker exec – it <Container> bash
o
Netstat -tunlp
VOLUME
ü
Volume is nothing but Mount Points.
ü
In our server one directory unnamed volume will
be mounted with the container directory (/var/Jenkins_home).
o How to retain the data/ stat of container using VOLUME?
======================================================================================================
Video 11 Troubleshoot
MithunTechnologiesDevOps/Dockerfile
·
If required we want to create a base image.
·
Alpine Linux (Less weight image compare to other
Linux distributions).
Best practice to be followed
while creating Image? * * * * * * * * *
1.
Use Alpine base images where ever it’s required.
2.
Use official images from Docker Hub.
3.
Don’t install/Copy un-necessary files/packages
(Software’s) in the image.
4.
Try to reduce the number of layers in image as
much as ASAP.
5.
Run your Process (application/Container) as a
non-root user.
6.
Try to scan (Clair, Sonarqube) Docker image to
identify vulnerabilities.
7.
Use multistage Dockerfile where it’s applicable.
Multistage Dockerfile?
Can we have more than one FROM
instruction in Dockerfile?
·
Yes ------Multistage Dockerfile
======================================================================================================
Video 12
Monolithic Architecture & Micro
Service Architecture:
Micro Services are very will work with container
·
Monolithic
Architecture:
o
It’s developmental approach (or) Architecture.
o
It application (Project) is developed in Monolithic
Architecture all the features/Modules are developed, build and deploy in a
single entity (Package).
§
Netflix
§
Uber
§
Flipkart
o Advantages
and dis-advantages of Monolithic Architecture
§ Simple
to develop
§ Simple
to deploy single package (jar/war/ear…..etc.,)
§
Easy to debug & Error Tracking.
§
Simple to test.
·
Tightly coupled.
·
Redeploy entire app on each update.
·
Single bug can bring down entire application.
·
Difficult to understand and modify.
·
Scaling the application is difficult.
·
If we need to scale only few features/modules
will end up scaling entire app as its single package.
·
Micro Service
Architecture:
o
Instated of developing that entire application
(Package).
o
We can break that application in to a small
applications/Service (features/ module).
o
Which can be developed, deploy & maintained
independently.
o
Flipkart
§
Registration
§
Login
§
Checkout
§
Products
§
Payments
§
Orders
§
Profile
·
UI
·
Business logic
·
Database (Data Interface)
o
Advantages and dis-advantages of Micro
Service Architecture
§
Loosely coupled.
§
Easy to understand & modify as it’s small
code base.
§
Better deployment as each service
(feature/module) can be deployed independently.
§
Each service can be scaled independently as each
service is a separate package.
§
Each service can be deployed using any new
technology as each service is a separate code base (Repository).
·
Deployment Challenges
·
Debugging problems can be harder
·
Communication between services is complex.
YouTube: ELK (EFK)
======================================================================================================
Video 13
Docker Network
It’s kind of a Software networking.
By default we have 3 docker networks created.
1.
Bridge (default network)
2.
Host
3.
None/null
o
Docker network ls ---------------------------To
see the network list in container
o
Docker inspect <Container>
---------------To see on which network is working.
§
Docker exec – it
mavenwebapp bash
§
Curl – v telnet://<ContainerIP>:<ContainerPortnumber> ----------------------communicating api from
other container (Testing Rest API’s)
·
Curl –v <Container>:<ContainerPortnumber>/
·
Curl –v <Container>:<ContainerPortnumber>/api/tasks
======================================================================================================
Video 14
ECR
·
Elastic Container Registry.
·
Its managed registry by AWS (we can maintain
only docker images).
o ECR
§ Create
Repository
Docker Volume
Comments
Post a Comment