You are on page 1of 25

DOCKER and KUBERNETES Training

Trainer: http://abraarsyed.me/

https://kubernetes.io/blog/2020/12/02/dont-panic-kubernetes-and-docker/
Don't Panic: Kubernetes and Docker
Authors: Jorge Castro, Duffie Cooley, Kat Cosgrove, Justin Garrison, Noah Kantrowitz, Bob Killen, Rey
Lejano, Dan “POP” Papandrea, Jeffrey Sica, Davanum “Dims” Srinivas Kubernetes is deprecating Do...
kubernetes.io
004701550412

HKBK786925

648944

Capitalization Certificate No.000001038243 Created

Capitalization Certificate No.000001038244 Created .

2004 docker images

2005 docker run -it ubuntu:18.04 bash

2006 docker ps

2007 docker ps -l

2008 docker ps -a

2009 docker run -it ubuntu:18.04 bash

2010 docker ps -a
2011 docker rm awesome_allen

2012 docker ps -a

2013 docker ps -a | grep "ubuntu"

2014 docker ps -a

2015 docker ps -a | grep "ubuntu"

2016 docker rm e11f05dab404 228cc2f9582e

2017 docker ps -a | grep "ubuntu"

2018 docker ps -a

2019 docker run -it --rm ubuntu:18.04 bash

2020 docker run -it ubuntu:18.04 bash

1998 docker ps -a

1999 docker ps -a | grep "ubuntu"

2000 docker run -it ubuntu:18.04 bash

2001 docker ps -a | grep "ubuntu"

2002 docker rm condescending_kirch

2003 docker commit a0e0f3f68d77

2004 docker images

2005 docker tag 90922a834dbc my-image 1.0

2006 docker tag 90922a834dbc my-image:1.0

2007 docker images

2008 history

2009 docker ps -a | grep "ubuntu"

2010 docker commit modest_driscoll my-image-2:latest

2011 docker images

2012 docker run -it my-image:1.0 bash

2013 docker ps -a | grep "ubuntu"

2014 docker rm modest_driscoll

2015 docker ps -a | grep "ubuntu"


To make the docker run without sudo command.

sudo groupadd docker

sudo gpasswd -a $USER docker

=================================

Also Install IBOSS

https://www.yammer.com/abb.com/#/files/311563321344

---------------------

TO Test if Docker is installed correctly.

------------------------------------------

2022 docker run hello-world

2023 docker images

---------------------------------------

2024 docker ps -a | grep "bash"

2025 docker rm inspiring_napier

2026 docker run -it ubuntu:18.04 sleep 5

2027 docker ps -a | grep "ubuntu"

2028 docker run -it ubuntu:18.04 bash -c "sleep 3; echo all done"

2029 docker run -it ubuntu:18.04 bash

2030 docker ps -a | grep "ubuntu"

2031* docker run -d -it ubuntu:18.04 bash

2032 docker ps -a | grep "ubuntu"

2033 docker ps -a | grep "ubuntu" | awk `{print $1}`

2034 docker ps -a | grep "ubuntu" | awk '{print $1}'


2035 docker ps -a | grep "ubuntu" | awk '{print $1}' | xargs docker rm

2036 docker ps -a | grep "ubuntu"

2037 docker run -d -it ubuntu:18.04 bash

2038 docker ps -a | grep "ubuntu"

2039 docker attach eager_mcnulty

2040 docker ps -a | grep "ubuntu"

2041 docker attach eager_mcnulty

2042 docker ps -a | grep "ubuntu"

2043 docker start eager_mcnulty

2044 docker ps -a | grep "ubuntu"

2045 docker stop eager_mcnulty

2046 docker ps -a | grep "ubuntu"

2047 docker start eager_mcnulty

2048 docker ps -a | grep "ubuntu"

2049 docker kill eager_mcnulty

2050 docker ps -a | grep "ubuntu"

2051 docker start eager_mcnulty

2052 docker ps -a | grep "ubuntu"

2053 docker attach eager_mcnulty

2054 docker ps -a | grep "ubuntu"

2055 docker exec -it eager_mcnulty bash

2056 docker ps -a | grep "ubuntu"

2057 docker attach eager_mcnulty

2058 docker ps -a | grep "ubuntu"

2059 docker start eager_mcnulty

2060 docker attach eager_mcnulty

2061 docker start eager_mcnulty

2062 docker exec -it eager_mcnulty bash

2063 docker ps -a | grep "ubuntu"


2064 docker rm eager_mcnulty

2065 docker rm -f eager_mcnulty

2066 docker ps -a | grep "ubuntu"

2067 docker run -it --rm --name my-first-docker-container ubuntu:18.04 bash

2068 docker ps -a | grep "ubuntu"

2069 docker run -it --name my-first-docker-container ubuntu:18.04 bash

2070 docker ps -a | grep "ubuntu"

2071 docker rm my-first-docker-container

2072 docker ps -a | grep "ubuntu"

2073 docker run --name my-container -d ubuntu:18.04 bash -c "lose /etc/password"

2074 docker ps -a | grep "ubuntu"

2075 docker logs my-container

----------------------------------------------------

Command to limit memory

------------------------

$ docker run -it \

--cpu-rt-runtime=950000 \

--ulimit rtprio=99 \

--cap-add=sys_nice \

debian:jessie

parameters --> --memory --cpu-shares --cpu-quota

------------------------------------------------------

[12/4 12:39 PM] Abraar Syed

docker images

1971 ls

1972 cd /

1973 ls
1974 cd home

1975 ls

1976 docker ps

1977 docker run -it ubuntu:18.04 bash

1978 docker ps -a

1979 docker ps -a | grep "ubuntu"

1980 docker run -it ubuntu:18.04 bash

1981 docker ps -a | grep "ubuntu"

1982 docker rm condescending_kirch

1983 docker commit a0e0f3f68d77

1984 docker images

1985 docker tag 90922a834dbc my-image 1.0

1986 docker tag 90922a834dbc my-image:1.0

1987 docker images

1988 history

1989 docker ps -a | grep "ubuntu"

1990 docker commit modest_driscoll my-image-2:latest

1991 docker images

1992 docker run -it my-image:1.0 bash

1993 docker ps -a | grep "ubuntu"

1994 docker rm modest_driscoll

1995 docker ps -a | grep "ubuntu"

1996 history

1997 exit

1998 docker attach eager_mcnulty

1999 docker exec -it eager_mcnulty bash

2000 docker ps -a | grep "ubuntu"

==========================================
docker history dbf995fc07ff

//its shows the container size

=====================================

[12/4 1:21 PM] Abraar Syed

2094 mkdir example

2095 ls

2096 pwd

2097 cd example/

2098 pwd

2099 cd ..

2100 ls

2101 docker run -it -v /home/jnaapti/example

2102 docker run -it -v /home/jnaapti/example:/shared-folder ubuntu:18.04 bash

2103 docker ps -a | grep "ubuntu"

2104 docker rm condescending_sammet

2105 docker ps -a | grep "ubuntu"

2106 docker run -it -v /home/jnaapti/example:/shared-folder ubuntu:18.04 bash

2107 docker ps -a | grep "ubuntu"

2108 docker rm -f compassionate_chaplygin flamboyant_wing

2109 ls

2110 cd example/

2111 ls

2112 cat example1.txt

2113 cat example2.txt

2114 ls -la

2115 docker images

2116 cd ..

2117 ls
2118 docker run -it -v /shared-folder ubuntu:18.04 bash

2119 ls

2120 rm -r example

2121 ls

2122 mkdir example-1 example-2

2123*

2124 docker run -it -v /home/jnaapti/example-1:/shared-folder-1 ubuntu:18.04 bash

2125 docker ps -a | grep "ubuntu"

2126 docker rm keen_bhabha heuristic_moser naughty_jennings

2127 docker ps -a | grep "ubuntu"

2128 ls

2129 cd example-1/

2130 ls

2131 cd ../example-2/

2132 ls

2133 cd ..

2134 rm example-1 example-2

2135 rm -r example-1 example-2

2136 ls

==============================================

2003 cd example/

2004 ls

2005 ls -ls

2006 ls

2007 cat greeting my-file

2008 docker ps -a

2009 docker inspect flamboyant_wing

2010 docker images


2011 docker run -it -v /home/jnaapti/example:/shared-folder ubuntu:18.04 bash

2012 docker ps -a | grep "ubuntu"

2013 docker run -it --volumes-from eloquent_lederberg ubuntu:18.04 bash

2014 docker ps -a | grep "ubuntu"

2015 docker rm priceless_kilby

2016 docker ps -a | grep "ubuntu"

2017 docker rm priceless_kilby

2018 docker ps -a | grep "ubuntu"

2019 docker rm eloquent_lederberg

2020 docker ps -a | grep "ubuntu"

2021 docker run -it -v /home/jnaapti/example-1:/shared-folder-1 ubuntu:18.04 bash

============================================

[12/4 1:22 PM] Abraar Syed

1989 docker ps -a | grep "ubuntu"

1990 docker commit modest_driscoll my-image-2:latest

1991 docker images

1992 docker run -it my-image:1.0 bash

1993 docker ps -a | grep "ubuntu"

1994 docker rm modest_driscoll

1995 docker ps -a | grep "ubuntu"

1996 history

1997 exit

1998 history

1999 docker run -it -v /home/jnaapti/example-2:/shared-folder-2 ubuntu:18.04 bash

-=============================================

nc -lp 1234

nc 127.0.0.1 1234
//as listerner

------------------------------------

nc -lp 1234 | tee | nc -lp 5678 this can show msg from both client

------------------------------------------

[12/4 2:55 PM] Abraar Syed

2139 apt-get update && apt-get install -y netcat

2140 nc

2141 nc -lp 1234

2142 nc -lp 1234 | nc -lp 5678

2143 docker ps -a | grep "ubuntu"

2144 docker run -it -p 1234:1234 -p 5678:5678 --name my-container ubuntu:18.04 bash

2145 docker ps -a | grep "ubuntu"

2146 docker rm -f my-container

2147 docker ps -a | grep "ubuntu"

2148 docker run -it -p 1234 -p 5678 --name my-container ubuntu:18.04 bash

2149 clear

2150 docker ps -a | grep "ubuntu"

2151 docker rm my-container

2152 docker ps -a | grep "ubuntu"

2153 docker run -it -p 1234:1234 -p 5678:5678 --name my-server ubuntu:18.04 bash

[12/4 2:55 PM] Abraar Syed

2024 nc 127.0.0.1 1234

2025 docker ps -a | grep "ubuntu"

2026 nc 127.0.0.1 32773

2027 clear

2028 docker run -it ubuntu:18.04 bash

=================================================

2002 nc 127.0.0.1 5678


2003 nc 127.0.0.1 32772

2004 clear

2005 docker run -it ubuntu:18.04 bash

================================

apt-get update && apt-get install -y netcat

-----------------------------------------

[12/4 3:32 PM] Abraar Syed

2158 docker network ls

2159 docker network create learning

2160 docker network ls

2161 docker run --rm -it --net learning --name catserver ubuntu:18.04 bash

--------------------------------------

2028 docker run -it ubuntu:18.04 bash

2029 history

2030 docker run --rm -it --net learning --name dogserver ubuntu:18.04 bash

=-----------------------------------

2005 docker run -it ubuntu:18.04 bash

2006 history

2007 ifconfig

2008 docker run -d -it --name ratserver ubuntu:18.04 bash

2012 docker network connect learning ratserver

2013 docker attach ratserver

-----------------------------------------------

https://hub.docker.com/_/microsoft-dotnet-samples/

//.NEt sample applications

//sample docker file


https://github.com/dotnet/dotnet-docker/blob/master/samples/dotnetapp/Dockerfile

--------------------------------------------------------------

[12/4 4:45 PM] Abraar Syed

Create Dockerfile containing all necessary softwares

2. Build the docker image using Dockerfile

3. Push this docker image to some cloud image registry

4. Other machines can pull this image and create the docker containers

------------------------------------------------------------------

FROM ubuntu:18.04

FROM ubuntu:18.04

RUN apt-get update

RUN apt-get install -y curl

RUN curl https://google.com | wc -c > google-size

ENTRYPOINT echo google size is as follows; cat google-size

------------------------------------------------

FROM ubuntu:18.04 as builder

RUN apt-get update

RUN apt-get install -y curl

RUN curl https://google.com | wc -c > google-size

FROM alpine

COPY --from=builder /google-size /google-size

ENTRYPOINT echo google size is as follows; cat google-size

----------------------------------------------------

https://docs.docker.com/engine/reference/builder/#arg

----------------------------------------------

[12/4 5:43 PM] Ahtesh Inamdar


Docker on Linux requires special configuration as described here:
https://docs.docker.com/network/proxy/.

Example of ~/.docker/config.json file:

"proxies":

"default":

"httpProxy": "http://127.0.0.1:8009",

"httpsProxy": "http://127.0.0.1:8009",

"noProxy": "127.0.0.1"

Configure Docker to use a proxy serverHow to configure the Docker client to use a proxy
serverdocs.docker.com

-----------------------------------------------------

Docker daemon itself may require additional configuration in /etc/systemd/system/docker.service.d/


folder as described here: https://docs.docker.com/config/daemon/systemd/.

The example configuration in /etc/systemd/system/docker.service.d/http-proxy.conf:

[Service]

Environment="HTTP_PROXY=http://127.0.0.1:8009/" "HTTPS_PROXY=http://127.0.0.1:8009/"
"NO_PROXY=localhost,127.0.0.1"

Containers must use “host” based networking to leverage iboss proxy available on host system (--
network="host" flag in docker run).

https://docs.docker.com/config/daemon/systemd/

----------------------------------------------------------
************************************************************************

DAY -2 (5/12/2020)

-----------------------

Docker Composer - Docker Composer Zip file

$ pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>

C:\Windows\System32\drivers\etc\hosts

[12/5 10:26 AM] Abraar Syed

https://docs.docker.com/engine/examples/dotnetcore/

https://docs.docker.com/compose/aspnet-mssql-compose/

Dockerize an ASP.NET Core applicationCreate a Docker image by layering your ASP.NET Core app on
debian for Linux Containers or with Windows Nano Server containers using a
Dockerfile.docs.docker.com

==============================================================

8**********************************************************************]]]

Installation for Kubernetes

Docker

Kubectl
Minikube

==============================================

[12/5 11:19 AM] Abraar Syed

https://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo

How can I use docker without sudo?On D### Setup Kubectl:

* Download link: https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-


curlocker's documentation pages, all example commands are shown without sudo, like this one:

docker ps

On Ubuntu, the binary is called docker.io. It also does not work without sudo:

sudo docker....askubuntu.com

==================================================

### Setup Kubectl:

* Download link: https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl

[12/5 1:16 PM] Abraar Syed

### Setup Kubectl:

* Download link: https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl

Command to test: `kubectl version`

### Setup Minikube:

* General Download Instructions: https://kubernetes.io/docs/tasks/tools/install-minikube/

* Download link: https://github.com/kubernetes/minikube/releases


Command to test: `minikube version`

[12/5 2:20 PM] Abraar Syed

Hey guys, please give me a quick hand raise once you are back (smile)

====================================================

For those, who are back already, please complete the installation for kubectl and minikube

[12/5 2:26 PM] Abraar Syed

https://minikube.sigs.k8s.io/docs/start/

=================================================

[12/5 2:47 PM] Abraar Syed

Hello World - Simple Pod and Service using commands

2040 kubectl config get-contexts

2041 kubectl get nodes

2042 kubectl get pods

2043 kubectl run hw --image=karthequian/helloworld --port=80

2044 kubectl get pods

2045 kubectl describe pod hw

2049 kubectl get pod/hw -o yaml

2051 kubectl get services

2053 kubectl expose pod hw --type=NodePort

2055 kubectl get services

2056 kubectl get service hw -o yaml

2057 kubectl get services

2058 minikube service hw


---------------------------------------------

[12/5 2:59 PM] Abraar Syed

2074 kubectl config get-contexts

2075 kubectl get all

2076 kubectl delete pod/hw

2077 kubectl get all

2078 kubectl delete service hw

2079 kubectl get all

2080 kubectl get pods

2081 kubectl get pods -n kube-system

2082 kubectl get pods -n A

2083 kubectl get pods -A

2084 k9s

2085 kubectl config get-contexts

2086 kubectx

2087 cd ~

2088 cd .kube/

2089 ls

2090 cat k3s.yaml

2091 kubectl get namespaces

2092 kubectl config get-contexts

===================================

[12/5 3:02 PM] Vinay Dev

PS C:\Vinay\Kube> minikube service hw

X Exiting due to SVC_NOT_FOUND: Service 'hw' was not found in 'default' namespace.
You may select another namespace by using 'minikube service hw -n <namespace>'. Or list out all the
services using 'minikube service list'

--------------------------------------

[12/5 3:22 PM] Narinder Pal

https://www.rorymon.com/blog/how-to-rdp-to-
ubuntu/#:~:text=Launch%20the%20RDP%20client%20on,able%20to%20work%20with%20it.

[12/5 3:27 PM] Abraar Syed

Creating Pod, Exposing Service

2. Checking on Browser

3. Exploring namespace, cluster, config

4. Deleting pod and service

-------------------------------------

[12/5 4:25 PM] Abraar Syed

Task:

kubectl run hw --image=karthequian/helloworld --port=80

kubectl expose pod hw --type=NodePort

This was creating the pod and service


I want you to write a deployment file for the deployment and service file for the above

----------------------------------

[12/5 4:28 PM] Abraar Syed

---

apiVersion: apps/v1

kind: Deployment

metadata:

name: mypod-deployment

spec:

selector:

matchLabels:

app: demo

env: test

replicas: 3

template:

metadata:

labels:

app: demo

env: test

spec:

containers:

- name: nginx

image: nginx

ports:

- name: http
containerPort: 80

protocol: TCP

---

apiVersion: v1

kind: Service

metadata:

name: mypod-service

spec:

type: NodePort

ports:

- port: 80

protocol: TCP

targetPort: 80

selector:

app: demo

---

=================================

kubectl create -f deploymentForAll.yml

yaml files are shared.

[12/5 5:00 PM] Abraar Syed

2148 kubectl get all

2149 kubectl scale --replicas=6 deployment helloworld-deployment

2150 kubectl get all

2151 kubectl scale --replicas=2 deployment helloworld-deployment

----------------------------------
APPENDIX

Install Docker Engine on Ubuntu


https://docs.docker.com/engine/install/ubuntu/

Docker Desktop for Mac and Win


https://www.docker.com/products/docker-desktop

docker-compose.zip
Docker Compose zip file.
Dockerfile
DOCKER FILE

HOST file.

Host
File_MicrosoftTeams-image.png

Kubernetes pods command

Kuberneters pods
command -MicrosoftTeams-image.png

Yaml files
mypod.yml

mypodservice.yml

deploymentForAll.ym
l

simple-all-using-repli
cationcontroller.yaml

training-hands-on.zip

You might also like