Docker Expounded

Steps to setup docker environment and Demo

  1. Docker Installation and it’s Life Cycle
  2. Demo of Docker Life Cycle with cpu, memory intensive workload (sysbench) and dstat monitoring tool as containers.

 

Step (A)

Docker Installation:  (on a rhel system)

 

Hello from Docker!

This message shows that your installation appears to be working correctly….

 

  • Start the docker daemon. “sudo dockerd &”

 

 

Docker Life-Cycle:  (on a rhel system)

  • Creating Docker File: In a new terminal say under folder /home/docker/cpu_cont/, create a docker file as below. (a docker Image)

 

File name should be “Dockerfile”: (CPU intensive workoad)

Bash#>/home/docker/cpu_cont>more Dockerfile

FROM centos:latest

RUN curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | bash
RUN yum -y install sysbench
CMD [“sysbench”, “–threads=50”, “–time=3600”, “–cpu-max-prime=1000”, “cpu”, “run”]

 

 

 

 

 

 

 

As shown below, similarly create the memory intensive workload and dstat monitoring tool, docker images under /home/docker/mem_cont/ and /home/docker/dstat_cont/ respectively.

Bash#>/home/docker/mem_cont> more Dockerfile

FROM centos:latest

RUN curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | bash

RUN yum -y install sysbench

CMD [“sysbench”, “–threads=20”, “–time=3600”, “memory”, “run”]

 

 

Bash#>/home/docker/dstat_cont> more Dockerfile

FROM centos:latest

RUN yum -y install dstat

CMD [“dstat”, “-tcmndylp”, “–top-cpu”]

  • Creating a registry to store images: Now create a registry in the system to push and pull images as needed.

Bash#> docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

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

Bash#> docker run -d -p 5000:5000 –restart=always –name registry registry:2

f9d3a0e22816c1ee4cf20b6cea25cd020ceb8e44db0a5a9daada9b95afa230db

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

Bash-4> docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES

f9d3a0e22816        registry:2          “/entrypoint.sh /etc…”   4 seconds ago       Up 3 seconds        0.0.0.0:5000->5000/tcp   registry

Bash#>

  • Creating a dockerhub in https://hub.docker.com/. Just signup with easy instructions on the portal.
  • Pushing existing images to the dockerhub repo. So I have docker login created in docker hub with login name as “lambzee” and hence to push locally created images.

Pushing the cpu image to dockerhub:

bash#> docker push lambzee/cpu:latest

The push refers to repository [docker.io/lambzee/cpu]

0ad8619a5950: Pushed

9f4917957ac9: Pushed

071d8bd76517: Mounted from library/centos

latest: digest: sha256:c12b6c3b61f40ffd811e79ce5b31c21a1532be8b1f0e2845028208a51089c932 size: 953

bash#>

 

Pushing the mem image to dockerhub lambzee:

bash#> docker push lambzee/mem:latest

The push refers to repository [docker.io/lambzee/mem]

0ad8619a5950: Mounted from lambzee/cpu

9f4917957ac9: Mounted from lambzee/cpu

071d8bd76517: Mounted from lambzee/cpu

latest: digest: sha256:107baac65649b0c01418ada047d4ca79c0b33d4d628e631dedef6a7d56d80371 size: 953

bash#>

 

The push can be verified by checking online at https://hub.docker.com as shown below.

docker_hub_pic

Step(B): Demo of Docker Life Cycle with cpu, memory intensive workload (sysbench) and dstat monitoring tool as containers.

We have seen how one can create an image of docker and push to docker hub. Now in below steps, we will see how dockers are run in detached mode and inspect them. Also how two started docker containers can be talk to each other and how you can convert an image into docker container and vice versa.

Finally conclude with docker-compose usage

Before we start, I would like to introduce to four network layout of the docker containers namely None, Bridge, Host and Overlay.

docker_nw

As shown above, when we start dockers in none network, they do not talk to each other and hence are isolated in the same docker host.  Now lets start cpu and dstat containers in none network.

bash#> docker run -d –net none lambzee/cpu:latest

7fae95a0ccd3a5f9a72047a9936e38e5d8721b0ea18291ae2d409489010f9fe3

bash#> docker ps

CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS               NAMES

7fae95a0ccd3        lambzee/cpu:latest   “sysbench –threads=…”   5 seconds ago       Up 5 seconds                            zen_chatterjee

bash#>

 

Also start the dstat monitor to run the dstat os monitoring tool in an another container as below.

bash#> docker run -d –net none lambzee/dstat:latest

b134f38793296493fb490c0a1652873040a63d8b26250bb553185a52089211e5

 

 

 

 

bash#> docker ps

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS               NAMES

b134f3879329        lambzee/dstat:latest   “dstat -tcmndylp –t…”   6 seconds ago       Up 5 seconds                            blissful_raman

57ca9ece9ec3        lambzee/cpu:latest     “sysbench –threads=…”   5 minutes ago       Up 5 minutes                            zen_chatterjee

bash#>

 

Let’s check what exactly if dstat container is connected to outside world using 10.115.50.32 ip i.e. my ILO IP compared to the host docker machine.

bash#> docker exec -it 57ca9ece9ec3 bash

[root@57ca9ece9ec3 /]# ping 10.115.50.32

connect: Network is unreachable

[root@57ca9ece9ec3 /]#

Let’s now see the host if connected to my ILO IP.

 

bash#> ping 10.115.50.32

PING 10.115.50.32 (10.115.50.32) 56(84) bytes of data.

64 bytes from 10.115.50.32: icmp_seq=1 ttl=255 time=0.348 ms

64 bytes from 10.115.50.32: icmp_seq=2 ttl=255 time=0.123 ms

64 bytes from 10.115.50.32: icmp_seq=3 ttl=255 time=0.131 ms

^C

— 10.115.50.32 ping statistics —

3 packets transmitted, 3 received, 0% packet loss, time 2003ms

rtt min/avg/max/mdev = 0.123/0.200/0.348/0.105 ms

bash#>

 

[root@57ca9ece9ec3 /]# ifconfig

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

inet 127.0.0.1  netmask 255.0.0.0

loop  txqueuelen 1000  (Local Loopback)

RX packets 0  bytes 0 (0.0 B)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 0  bytes 0 (0.0 B)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

[root@57ca9ece9ec3 /]#

The none n/w model above shows that we have loop back n/w is available where individual networks are suitable.

bash#> docker network  inspect none

[

{

“Name”: “none”,

“Id”: “93fe31b80ab4aef7d2fb70176c46b52c991c9d08d604b740e1b37fefe9496c1d”,

“Created”: “2018-08-02T08:37:50.850741608-04:00”,

“Scope”: “local”,

“Driver”: “null”,

“EnableIPv6”: false,

“IPAM”: {

“Driver”: “default”,

“Options”: null,

“Config”: []

},

“Internal”: false,

“Attachable”: false,

“Ingress”: false,

“ConfigFrom”: {

“Network”: “”

},

“ConfigOnly”: false,

“Containers”: {

“3cbef6faa8a997e109da0a1baf63b3ce09e5aab1ba55310e4aea61e3a4a2e01d”: {

“Name”: “stupefied_shtern”,

“EndpointID”: “25bcb01cbd3796c6d1fd5841adb145c68f1673dc75f29f1077b467df2fdff36e”,

“MacAddress”: “”,

“IPv4Address”: “”,

“IPv6Address”: “”

},

“55c1437c0daf152127947b999b9f86b3b1f39cfa7a01cf2633bdb3118e79f6ef”: {

“Name”: “compassionate_bhaskara”,

“EndpointID”: “f749c3cdd51b5e85a908ee61a95011634c61c69b066fe1cb2a5fad078717bb8f”,

“MacAddress”: “”,

“IPv4Address”: “”,

“IPv6Address”: “”

}

},

“Options”: {},

“Labels”: {}

}

]

bash#> docker ps

CONTAINER ID        IMAGE                  COMMAND                  CREATED              STATUS              PORTS               NAMES

55c1437c0daf        lambzee/cpu:latest     “sysbench –threads=…”   About a minute ago   Up About a minute                       compassionate_bhaskara

3cbef6faa8a9        lambzee/dstat:latest   “dstat -tcmndylp –t…”   3 minutes ago        Up 3 minutes                            stupefied_shtern

bash#>

 

 

 

 

 

 

 

 

Installation and Use of docker Compose:

Download and install docker-compose as below. Docker compose enabled execution of more than one service with desired container topology this enabling communication in a multi-container environment within a host or across hosts. In below case we have only within host communication shown.

    https://docs.docker.com/compose/install/

bash#> docker-compose: command not found
bash#> sudo curl -L “https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 617 0 617 0 0 1301 0 –:–:– –:–:– –:–:– 1304
100 11.2M 100 11.2M 0 0 873k 0 0:00:13 0:00:13 –:–:– 557k
bash#>

sudo chmod +x /usr/local/bin/docker-compose bash-4.2# docker-compose –version docker-compose version 1.23.2, build 1110ad01 bash#>

 

 

Docker-compose yml file is used to setup what services to run and what networks the services use and what topology is followed to connect these services. In below docker-compose.yml file I am using a separate yml file with a new directory created as below.

 

-bash-4.2# pwd

/home/hs/docker/compose

-bash-4.2#

 

-bash-4.2# more docker-compose.yml

version: “3”

services:

cpu:

image: lambzee/cpu:latest

depends_on:

– dstatmon

networks:

– my_net

mem:

image: lambzee/mem:latest

depends_on:

– dstatmon

networks:

– my_net

 

dstatmon:

image: lambzee/dstatmon:latest

networks:

– my_net

 

networks:

my_net:

driver: bridge

 

-bash-4.2#

 

 

 

From above we see that cpu and memory intensive workloads are started on common “my_net” networks and “bridge” driver. “depends_on” key word is used inorder to say a specific service cpu/mem can be monitored separately with dstat.

 

One can start the docker compose as below.

bash#> docker-compose up -d
Creating network “compose_my_net” with driver “bridge”
Creating compose_dstatmon_1 … done
Creating compose_mem_1 … done
Creating compose_cpu_1 … done
bash#>

bash#> more docker-compose.yml
version: “3”
services:
cpu:
image: lambzee/cpu:latest
depends_on:
– dstatmon
networks:
– my_net
mem:
image: lambzee/mem:latest
depends_on:
– dstatmon
networks:
– my_net

dstatmon:
image: lambzee/dstatmon:latest
networks:
– my_net

networks:
my_net:
driver: bridge

bash#>

bash#> docker network ls
NETWORK ID NAME DRIVER SCOPE
c70967cabb58 bridge bridge local
2a64a26e5fbf compose_my_net bridge local
14663c854d6b host host local
93fe31b80ab4 none null local
bash#>

 

One can stop the docker compose as below.

bash-4.2# docker-compose down
Stopping compose_cpu_1 … done
Stopping compose_dstatmon_1 … done
Removing compose_cpu_1 … done
Removing compose_mem_1 … done
Removing compose_dstatmon_1 … done
Removing network compose_my_net
bash#>

 

Future work:

To work on showing virtual machine to docker comparison and demonstration of services / containers across host swarm mode docker daemon and docker daemon in a VM , both connected by a overlay network.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s