Akhil Docker LAB

Docker Installation Guide

[root@localhost ~]# history
1 ifconfig
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-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
5 sudo yum install –y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
6 sudo yum-config-manager --enable rhui-REGION-rhel-server-extras
7 sudo yum install -y docker-ce
8 sudo yum install docker-ce
9 docker -v
10 sudo systemctl enable docker
11 sudo systemctl start docker
12 docker info
13 sudo docker run hello-world
14 history
[root@localhost ~]#

Verify if the docker is installed and running :

[root@localhost ~]# which docker
/bin/docker
[root@localhost ~]# which dockerd
/bin/dockerd
[root@localhost ~]# ps -eaf | grep dockerd
root 30370 1 0 01:14 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 30697 29997 0 01:19 pts/0 00:00:00 grep --color=auto dockerd
[root@localhost ~]# ps -eaf | grep docker
root 30370 1 0 01:14 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 30699 29997 0 01:19 pts/0 00:00:00 grep --color=auto docker
[root@localhost ~]#

Assignment 1# Creating an ubuntu container

[root@localhost ~]# 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

Attaching to the container and installing git and apache in it

root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
54585f25a19e httpd "httpd-foreground" 25 minutes ago Up 25 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp recursing_cray
37ac4f644b91 ubuntu "bash" 27 minutes ago Up 27 minutes silly_williams
f78f43296a42 httpd "httpd-foreground" 32 minutes ago Up 32 minutes 80/tcp reverent_cohen
15cbcb118557 httpd "httpd-foreground" 33 minutes ago Exited (0) 32 minutes ago boring_hypatia
c1e53557461d ubuntu "bash" 33 minutes ago Exited (127) 27 minutes ago romantic_maxwell
a21cccb03cc8 hello-world "/hello" 2 hours ago Exited (0) 2 hours ago hardcore_hypatia
[root@localhost ~]# docker attach 37ac4f644b91
root@37ac4f644b91:/bin#

Now installing git and apache2

root@37ac4f644b91:/bin# apt-get install git
Reading package lists… Done
Building dependency tree
Reading state information… Done
git is already the newest version (1:2.25.1-1ubuntu3.1).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
root@37ac4f644b91:/bin#

root@37ac4f644b91:/bin# apt-get install apache2
Reading package lists… Done
Building dependency tree
Reading state information… Done
apache2 is already the newest version (2.4.41-4ubuntu3.4).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
root@37ac4f644b91:/bin#

Since both are successfully installed now , come out of the container without exiting 

CTRL+P+Q

Commit the container changes


docker commit -m "ubuntu-git-apache" -a "Akhil" 37ac4f644b91 ubuntu-git-apache

Now see if the new image is created

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-git-apache latest e89de62b7ed9 15 minutes ago 257MB
ubuntu latest c29284518f49 7 days ago 72.8MB
httpd latest bd29370f84ea 12 days ago 138MB
hello-world latest d1165f221234 4 months ago 13.3kB
Verifying if Git is installed from out side of the container
[root@localhost ~]# docker exec -it 37ac4f644b91 /bin/git --version
git version 2.25.1
[root@localhost ~]#

Assignment 2 # Create a httpd container exposed at 8080 port

[root@localhost ~]# 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@localhost ~]# docker run -d httpd
8311be7b53072d56b6776e7e97b32c45630d22d07ac63167b22fd9ac27ebbe95
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE         COMMAND              CREATED         STATUS                            PORTS     NAMES
8311be7b5307   httpd         "httpd-foreground"   6 seconds ago   Up 5 seconds                      80/tcp    awesome_ptolemy
54585f25a19e   httpd         "httpd-foreground"   11 hours ago    Exited (137) About a minute ago             recursing_cray
37ac4f644b91   ubuntu        "bash"               11 hours ago    Up 11 hours                                 silly_williams
f78f43296a42   httpd         "httpd-foreground"   11 hours ago    Exited (137) About a minute ago             reverent_cohen
15cbcb118557   httpd         "httpd-foreground"   11 hours ago    Exited (0) 11 hours ago                     boring_hypatia
c1e53557461d   ubuntu        "bash"               11 hours ago    Exited (127) 11 hours ago                   romantic_maxwell
a21cccb03cc8   hello-world   "/hello"             12 hours ago    Exited (0) 12 hours ago                     hardcore_hypatia

[root@localhost ~]# docker run -d -p 80:80 httpd
c565adb8c408d4c751a5d66657a5563f5e3ab9fed29dbbc42a32a2a00458237d
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE         COMMAND              CREATED         STATUS                       PORTS                               NAMES
c565adb8c408   httpd         "httpd-foreground"   3 seconds ago   Up 3 seconds                 0.0.0.0:80->80/tcp, :::80->80/tcp   mystifying_mendeleev
8311be7b5307   httpd         "httpd-foreground"   2 minutes ago   Up 2 minutes                 80/tcp                              awesome_ptolemy
Access the url from outside
[root@localhost ~]# curl http://192.168.2.31:80
<html><body><h1>It works!</h1></body></html>

Assignment 3 #

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

Local registry is something that is present in the local file storage where you can find the images in the local file system;

To find it , execute docker info command , you would find an local Root Dir something like “Docker Root Dir: /var/lib/docker”,

and look for storage driver ; you would see something like “Storage Driver: overlay2” , that’s where you can find the local images

/var/lib/docker/image/overlay2/imagedb/content/sha256
[root@localhost sha256]# ls -latr
total 28
drwx——. 3 root root 20 Jul 21 01:14 ..
-rw——-. 1 root root 1470 Jul 21 01:15 d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
-rw——-. 1 root root 1462 Jul 21 02:02 c29284518f497b8c5f49933e74e43ca5221e69c8251e780427f7d12f716625ff
-rw——-. 1 root root 8701 Jul 21 02:09 bd29370f84eac6a9fa5373f8ed702f66820e784e5f680b62670af9f851017c96
-rw——-. 1 root root 1506 Jul 21 02:35 e89de62b7ed9b52593d2993a9c36184c64b44354cb726fc9ee59158495391605
drwx——. 2 root root 4096 Jul 21 02:35 .

Git is NOT versioning a file. So what?

Git is although considered as a version control system by most of the people , it is actually not a version control system , It merely is providing a way to collaborate to a project in a distributed fashion ;

The most basic thing that a version control system should do is store a version of all the changes that have been made to a project and revert to them at any time. Git can save versions of a project. However, what git can not do is let you checkout those versions without blowing up the system.

Say your master branch looks like this:

A – B – C – D – E (HEAD)

If you realized that you only want to get the contents of commit B, and discard the other changes, you have a slew of terrible options:

(1) git reset –hard B – This is an AWFUL option. You get a log that looks like this:

A – B (HEAD)

But you’ve just destroyed your entire history. Where’s C and D if you need them in the future?

(2) git revert E; git revert D; git revert C. This option is ridiculous. It makes no sense to manually enter all the commits you want to undo. What if the commit I want to revert to is 10 commits back?

(3) git checkout -f B — . This option doesn’t handle files created since B. You have to manually delete them!

I’d rather have a file system that has a directory for Version A, Version B, Version C, etc. of my project at this point than use git for version control.

What is diff between docker pause and docker unpuase?

docker pause command suspends all processes in the specified containers. On Linux, this uses the freezer cgroup. Traditionally, when suspending a process the SIGSTOP signal is used, which is observable by the process being suspended

docker unpause command un-suspends all processes in the specified containers. On Linux, it does this using the freezer cgroup.

What is significant of docker stop and docker kill?

The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL. The first signal can be changed with the STOPSIGNAL instruction in the container’s Dockerfile, or the –stop-signal option to docker run.

docker kill;subcommand kills one or more containers. The main process inside the container is sent SIGKILL;signal (default), or the signal that is specified with the;–signal;option. You can kill a container using the container’s ID, ID-prefix, or name.

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

[root@localhost centos]# docker build -t centos-git .
Sending build context to Docker daemon  2.048kB
Step 1/5 : FROM centos:latest
latest: Pulling from library/centos
7a0437f04f83: Pull complete
  perl-threads-shared-1.58-2.el8.x86_64

Complete!
Removing intermediate container 37517363cda6
 ---> 631a377aad7d
Step 5/5 : CMD ["google.com"]
 ---> Running in 82cfeeb696a1
Removing intermediate container 82cfeeb696a1
 ---> 528ca90cd42f
Successfully built 528ca90cd42f

[root@localhost centos]# docker images
REPOSITORY                             TAG       IMAGE ID       CREATED              SIZE
centos-git                             latest    528ca90cd42f   About a minute ago   641MB
akhilnalumachu/dockerlabjuly21         latest    e89de62b7ed9   11 hours ago         257MB
akhilnalumachu                         latest    e89de62b7ed9   11 hours ago         257MB
ubuntu-git-apache                      latest    e89de62b7ed9   11 hours ago         257MB
akhilnalumachu/dockerdockerlabjuly21   latest    e89de62b7ed9   11 hours ago         257MB
ubuntu                                 latest    c29284518f49   7 days ago           72.8MB
httpd                                  latest    bd29370f84ea   12 days ago          138MB
hello-world                            latest    d1165f221234   4 months ago         13.3kB
centos                                 latest    300e315adb2f   7 months ago         209MB