Hemanth- Docker LAB

Install Docker Engine in Centos#1 Vm.

[root@pks]# history
1 clear
2 sudo yum install -y yum-utils device-mapper-persistent-data lvm2
3 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
4 sudo yum install –y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
5 sudo yum-config-manager --enable rhui-REGION-rhel-server-extras
6 sudo yum install -y docker-ce

Verification :

[root@pks ~]# cd
[root@pks ~]# which dockerd
/bin/dockerd
[root@pks ~]# which docker
/bin/docker
[root@pks ~]# ps -eaf | grep dockerd
root 951 1 0 03:32 ? 00:00:01 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 1783 1759 0 05:00 pts/1 00:00:00 grep --color=auto dockerd
[root@pks ~]# which containerd
/bin/containerd
[root@pks ~]# ps -eaf | grep containerd
root 862 1 0 03:32 ? 00:00:06 /usr/bin/containerd
root 951 1 0 03:32 ? 00:00:01 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 1787 1759 0 05:00 pts/1 00:00:00 grep --color=auto containerd
[root@pks ~]# which docker
/bin/docker
[root@pks ~]# cd
[root@pks ~]# which dockerd
/bin/dockerd
[root@pks ~]# which docker
/bin/docker
[root@pks ~]# ps -eaf | grep dockerd
root 951 1 0 03:32 ? 00:00:01 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 1783 1759 0 05:00 pts/1 00:00:00 grep --color=auto dockerd
[root@pks ~]# which containerd
/bin/containerd
[root@pks ~]# ps -eaf | grep containerd
root 862 1 0 03:32 ? 00:00:06 /usr/bin/containerd
root 951 1 0 03:32 ? 00:00:01 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 1787 1759 0 05:00 pts/1 00:00:00 grep --color=auto containerd

Assignment#1

Create a Ubuntu container

[root@pks ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
Digest: sha256:b3e2e47d016c08b3396b5ebe06ab0b711c34e7f37b98c9d37abe794b71cea0a2
Status: Image is up to date for ubuntu:latest
docker.io/library/ubuntu:latest

[root@pks ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND              CREATED          STATUS                      PORTS     NAMES
8e6af5cf67b3   ubuntu    "bash"               27 seconds ago   Exited (0) 26 seconds ago             silly_boyd

[root@pks ~]# docker images
REPOSITORY               TAG       IMAGE ID       CREATED        SIZE

ubuntu                   latest    c29284518f49   7 days ago     72.8MB

Install Update, git & apache2

[root@pks ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@pks ~]# docker images
REPOSITORY               TAG       IMAGE ID       CREATED        SIZE

ubuntu                   latest    c29284518f49   7 days ago     72.8MB

[root@pks]# docker run -itd ubuntu
da2946cadce9993be089119595c07b2bf9023cc6fe8484e382ba40b699d2ff0a
[root@pks]# docker ps -a
CONTAINER ID   IMAGE     COMMAND              CREATED         STATUS         PORTS                                   NAMES
da2946cadce9   ubuntu    "bash"               6 seconds ago   Up 5 seconds                                           focused_sinoussi

root@da2946cadce9:/# apt install git

root@da2946cadce9:/# git version
git version 2.25.1

root@da2946cadce9:/# apt install apache2
root@da2946cadce9:/# apache2 -version
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2021-07-05T07:16:56

Press Ctl+p+q ( to exit if you are in bash )

Assignment#2

Create a httpd container exposed at 8080 port

[root@pks]# docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
Digest: sha256:1fd07d599a519b594b756d2e4e43a72edf7e30542ce646f5eb3328cf3b12341a
Status: Image is up to date for httpd:latest
docker.io/library/httpd:latest

[root@pks]# docker images|grep httpd
httpd                    latest    bd29370f84ea   12 days ago    138MB

[root@pks]# docker run -d -p 8080:80 --name webserver httpd
e18a1c96c9b1ab7a688f2cd2beb0eaba6874a17c4955a4e41ffe98e68bbf76e9

[root@pks]# docker ps -a
CONTAINER ID   IMAGE     COMMAND              CREATED          STATUS          PORTS                                   NAMES
e18a1c96c9b1   httpd     "httpd-foreground"   26 seconds ago   Up 25 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   webserver

[root@pks]# docker attach da2946cadce9

root@da2946cadce9:/# apt update

Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [985 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [428 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:9 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [32.7 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [784 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1417 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1055 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [37.3 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [474 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [2668 B]
Get:18 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [6303 B]
Fetched 18.6 MB in 7s (2487 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done






run a git command in container from outside

[root@pks]# docker exec fb96ba213cac git version
git version 2.25.1

Access(curl) container from node

[root@pks]# wget localhost:8080
--2021-07-21 06:00:02--  http://localhost:8080/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45 [text/html]
Saving to: ‘index.html.1’

100%[=========================================================================================================================================================>] 45          --.-K/s   in 0s

2021-07-21 06:00:02 (3.70 MB/s) - ‘index.html.1’ saved [45/45]

Assignment#3

– Where is the LOCAL Registry and How do i find out???

By using docker info we can fine . 

[root@pks]# docker info
Docker Root Dir: /var/lib/docker 

[root@pks]# ll
total 8
drwx--x--x.  4 root root  120 Jul 20 06:06 buildkit
drwx-----x.  4 root root  150 Jul 21 06:28 containers
drwx------.  3 root root   22 Jul 20 06:06 image
-rw-r--r--.  1 root root 1388 Jul 21 06:51 info
drwxr-x---.  3 root root   19 Jul 20 06:06 network
drwx-----x. 16 root root 4096 Jul 21 06:28 overlay2
drwx------.  4 root root   32 Jul 20 06:06 plugins
drwx------.  2 root root    6 Jul 21 03:32 runtimes
drwx------.  2 root root    6 Jul 20 06:06 swarm
drwx------.  2 root root    6 Jul 21 03:32 tmp
drwx------.  2 root root    6 Jul 20 06:06 trust
drwx-----x.  2 root root   50 Jul 21 03:32 volumes

[root@pks]# cd overlay2
[root@pks]# ll
total 4
drwx-----x. 5 root root   69 Jul 21 06:28 2084f702d84cea4437d29d75d7bdb298c6423960f92937e645e7b357dbd60611
drwx-----x. 4 root root   72 Jul 21 06:28 2084f702d84cea4437d29d75d7bdb298c6423960f92937e645e7b357dbd60611-init
drwx-----x. 4 root root   72 Jul 20 06:08 3582fc98eadb391e96c56471e63e75a373347b041cc0830d64d0191aa86d2dad
drwx-----x. 4 root root   72 Jul 20 06:08 4042334baa7104f5f3c37c24933f4b48ebafd9b43fdcfbff8427cf7f6f100427
drwx-----x. 4 root root   72 Jul 20 06:08 44e3377d7f847deb718d8bc7cf6973c73ca66b32fbf3678e7a78a58b920d3aec
drwx-----x. 4 root root   55 Jul 21 06:28 5bcfff4c60322476d07f60b7f14e58bba39f4fa9beabf56a263540e263c6d743
drwx-----x. 4 root root   72 Jul 21 06:28 5bcfff4c60322476d07f60b7f14e58bba39f4fa9beabf56a263540e263c6d743-init
drwx-----x. 3 root root   47 Jul 21 05:14 72a82d12de04aea06a4c2d6735541eb453f445cfe2234d94a864f108094248f7
drwx-----x. 3 root root   47 Jul 20 07:04 88ffbaf180e0ae193119811a9990dd96ce95f666a4c23955fd94d3b5f5651053
drwx-----x. 4 root root   72 Jul 20 06:08 8a838646394c6c762c14ae565e4b9f00f8d3c5d45f4084aafad52e59c735f91d
drwx-----x. 4 root root   55 Jul 20 07:24 8f4f85670ff3710089f99a38b811d09acc26fa62f4de44f166e42d61d03f82a8
brw-------. 1 root root 8, 2 Jul 21 03:32 backingFsBlockDev
drwx-----x. 3 root root   47 Jul 20 06:08 e6059da5aaeb1b5715ed5709379b39f941b8f0fafc6f24b18709685d534e5f8e
drwx-----x. 4 root root   55 Jul 20 07:13 f4d3f3f0f672576f349e15cd511ee932f678fa6fa0f17fd7a40382afec38fa3f
drwx-----x. 2 root root 4096 Jul 21 06:28 l

– What is diff between docker pause and docker unpuase?

commands to pause and resume containers

– What is significant of docker stop and docker kill?

if you wish to soft stop we will use stop . 
Kill for will force shut down

Create an image with base – centos and git must be installed in it.

[root@pks]# docker run -itd centos
06e615d2e0d14caed3628301dc4db4bf23dd726584df0a88f250003486a7a786


[root@pks]# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                      PORTS     NAMES
06e615d2e0d1   centos    "/bin/bash"   28 seconds ago   Up 27 seconds                         magical_shockley


[root@pks]# docker attach 06e615d2e0d1

[root@06e615d2e0d1 /]# git --version
git version 2.27.0

[root@pks-wells ~]# docker commit -m "installed httpd and git" -a "HemanthVusirika" 06e615d2e0d1 centos-git-21-0

[root@pks]# docker images
REPOSITORY               TAG       IMAGE ID       CREATED         SIZE
centos-git-21-07         latest    d8795fb9189b   8 seconds ago   335MB