DOCKER CONCEPT FOR DBA – PART 8 How to build docker image from docker file

1.You need to create docker file first.Below is example of small test docker file.

root@deb-VirtualBox:~# cat test_docker.file
 FROM centos:latest
 RUN yum update -y

Here please note that FROM clause denotes first we need to pull centos image and RUN clause will run yum update on top of it.

2.Now I will build the docker image .

-t option is used to provide tag name

-f option is used to provide docker file name.

You need to run the following command from same path where your docker file resides.

root@deb-VirtualBox:~# docker build -t customimage:v1 -f test_docker.file .
 Sending build context to Docker daemon 8.704kB
 Step 1/2 : FROM centos:latest
 latest: Pulling from library/centos
 469cfcc7a4b3: Pull complete
 Digest: sha256:989b936d56b1ace20ddf855a301741e52abca38286382cba7f44443210e96d16
 Status: Downloaded newer image for centos:latest
 ---> e934aafc2206
 Step 2/2 : RUN yum update -y
 ---> Running in 21686d3260e4
 Loaded plugins: fastestmirror, ovl
 http://ftp.iitm.ac.in/centos/7.4.1708/updates/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://ftp.iitm.ac.in/centos/7.4.1708/updates/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
 Trying other mirror.
 Determining fastest mirrors
 * base: mirror.nbrc.ac.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
 No packages marked for update
 Removing intermediate container 21686d3260e4
 ---> 9528f83769a3
 Successfully built 9528f83769a3
 Successfully tagged customimage:v1

3.Now let me run the docker image command to check details of our latest build

root@deb-VirtualBox:~# docker images

Please note centos image has been pulled and on top of it our customimage has been built.

4.Now you can use no-cache during pull the image

root@deb-VirtualBox:~# docker build --pull --no-cache -t optimized:v1 -f test_docker.file .
 Sending build context to Docker daemon 8.704kB
 Step 1/2 : FROM centos:latest
 latest: Pulling from library/centos
 Digest: sha256:989b936d56b1ace20ddf855a301741e52abca38286382cba7f44443210e96d16
 Status: Image is up to date for centos:latest
 ---> e934aafc2206
 Step 2/2 : RUN yum update -y
 ---> Running in b2319a7d1d89
 Loaded plugins: fastestmirror, ovl
 http://ftp.iitm.ac.in/centos/7.4.1708/updates/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://ftp.iitm.ac.in/centos/7.4.1708/updates/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
 Trying other mirror.
 Determining fastest mirrors
 * base: del-mirrors.extreme-ix.org
 * extras: del-mirrors.extreme-ix.org
 * updates: del-mirrors.extreme-ix.org
 No packages marked for update
 Removing intermediate container b2319a7d1d89
 ---> dd055168eb91
 Successfully built dd055168eb91
 Successfully tagged optimized:v1

5.Now let me write complex docker file

root@deb-VirtualBox:~# cat mycomplexdockerfile.file
FROM centos:6
LABEL maintainer="debasis.tcs@gmail.com"
RUN yum update -y && yum install -y httpd net-tools
RUN mkdir -p /run/httpd
RUN rm -rf /run/http/* /tmp/httpd*
CMD echo "Remember to check your container IP address"
ENV ENVIRONMENT="production"
EXPOSE 80
ENTRYPOINT apachectl "-DFOREGROUND"

6.Let me explain the syntex which we used above

 

FROM centos:6 (This will pull centos image as base)
LABEL maintainer=”debasis.tcs@gmail.com” (This is deprecated)
RUN yum update -y && yum install -y httpd net-tools(It will run all yum package install command)
RUN mkdir -p /run/httpd (Create directory)
RUN rm -rf /run/http/* /tmp/httpd* (Remove directory)
CMD echo “Remember to check your container IP address” (Echo something important)
ENV ENVIRONMENT=”production” (Setting env variable)
EXPOSE 80 (The apache service will listener to port 80)
ENTRYPOINT apachectl “-DFOREGROUND”

 

7.Building docker image

docker build -t mywebserver:v1 -f mycomplexdockerfile.file .

8.Please check the image again

root@deb-VirtualBox:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mywebserver v1 a23dab42b0ee 7 minutes ago 321MB
optimized v1 dd055168eb91 11 hours ago 301MB
customimage v1 9528f83769a3 11 hours ago 301MB
hello-world latest e38bc07ac18e 2 weeks ago 1.85kB
centos 6 70b5d81549ec 3 weeks ago 195MB
centos latest e934aafc2206 3 weeks ago 199MB
root@deb-VirtualBox:~# docker run -d --name mytestweb --rm mywebserver:v1
c0d3e30d1ab22523e7be4958f15cad6dca122a368306a23dd1573a958adabebd

9.Please check that docker is running now

root@deb-VirtualBox:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0d3e30d1ab2 mywebserver:v1 "/bin/sh -c 'apachec…" 45 seconds ago Up 44 seconds 80/tcp mytestweb

10.Let me check IP address of the docker

root@deb-VirtualBox:~# docker inspect mytestweb | grep -i ipaddress
 "SecondaryIPAddresses": null,
 "IPAddress": "172.17.0.2",
 "IPAddress": "172.17.0.2",

11.Let me check using elinks

root@deb-VirtualBox:~# elinks http://172.17.0.2

12.Now we can use argument in docker file

root@deb-VirtualBox:~# cat mycomplexdockerfile_arg.file
ARG TARGETVERSION=6
FROM centos:${TARGETVERSION}
LABEL maintainer="debasis.tcs@gmail.com"
RUN yum update -y && yum install -y httpd net-tools
RUN mkdir -p /run/httpd
RUN rm -rf /run/http/* /tmp/httpd*
CMD echo "Remember to check your container IP address"
ENV ENVIRONMENT="production"
EXPOSE 80
ENTRYPOINT apachectl "-DFOREGROUND"

13.I will again re-build the docker

root@deb-VirtualBox:~# docker build -t mywebserver1:v1 -f mycomplexdockerfile_arg.file .

14.We can check history of command executed in docker build

root@deb-VirtualBox:~# docker image history mywebserver1:v1

15.You may use no-trunc option to see full command line used in docker run

DOCKER CONCEPT FOR DBA – PART 7 Pull docker image from repository

Docker hub is repository of images for Community Edition.

1.Checking docker images available in server

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


2.Let me try to pull a demo project

[root@debasiseric3 ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latest

3.Let me check what latest images pulled.


[root@debasiseric3 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest e38bc07ac18e 4 days ago 1.85kB

4.Now I can pull all packages along with latest

[root@debasiseric3 ~]# docker pull -a hello-world
latest: Pulling from library/hello-world
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
linux: Pulling from library/hello-world
Digest: sha256:c04eb928016c5ba813819c544ed97c24301e8a0a2b5f078a760024a30e861d19
nanoserver-1709: Pulling from library/hello-world
no matching manifest for linux/amd64 in the manifest list entries

5.Let me see all docker images pulled now

[root@debasiseric3 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest e38bc07ac18e 4 days ago 1.85kB
hello-world linux e38bc07ac18e 4 days ago 1.85kB


6.Download docker images which is automatically trusted by repository

[root@debasiseric3 ~]# docker pull --disable-content-trust hello-world
Using default tag: latest
latest: Pulling from library/hello-world
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Image is up to date for hello-world:latest

7.Please run the hello-world after instantiating docker.

[root@debasiseric3 ~]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 (amd64)
 3. The Docker daemon created a new container from that image which runs the
 executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
 to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

8.Now using following command,I can see long image id.

[root@debasiseric3 ~]# docker images --digests
REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
hello-world latest sha256:c04eb928016c5ba813819c544ed97c24301e8a0a2b5f078a760024a30e861d19 e38bc07ac18e 4 days ago 1.85kB
hello-world latest sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77 e38bc07ac18e 4 days ago 1.85kB
hello-world linux sha256:c04eb928016c5ba813819c544ed97c24301e8a0a2b5f078a760024a30e861d19 e38bc07ac18e 4 days ago 1.85kB
hello-world linux sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77 e38bc07ac18e 4 days ago 1.85kB

9.Let me pull centos image of version 6 using filter

[root@debasiseric3 ~]# docker pull centos:6
6: Pulling from library/centos
987d765a926d: Pull complete
Digest: sha256:67b491e26d566ee9c55578bfd6115554a6e1b805a49502ead32cb1a324466f2c
Status: Downloaded newer image for centos:6

10.Now checking docker images again.

[root@debasiseric3 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest e38bc07ac18e 4 days ago 1.85kB
hello-world linux e38bc07ac18e 4 days ago 1.85kB
centos 6 70b5d81549ec 9 days ago 195MB

11.Displaying full image information

[root@debasiseric3 ~]# docker images --no-trunc
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest sha256:e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96 4 days ago 1.85kB
hello-world linux sha256:e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96 4 days ago 1.85kB
centos 6 sha256:70b5d81549ec19aa0a10f8660ba5e1ab9966008dbb1b6c5af3d0ecc8cff88eef 9 days ago 195MB

12.Review only the image id

[root@debasiseric3 ~]# docker images -q
e38bc07ac18e
e38bc07ac18e
70b5d81549ec

13.Filter the most rated docker images

[root@debasiseric3 ~]# docker search --filter stars=50 apache
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementati… 1802 [OK]
httpd The Apache HTTP Server Project 1634 [OK]
cassandra Apache Cassandra is an open-source distribut… 755 [OK]
maven Apache Maven is a software project managemen… 580 [OK]
solr Solr is the popular, blazing-fast, open sour… 518 [OK]
zookeeper Apache ZooKeeper is an open-source server wh… 353 [OK]
eboraas/apache-php PHP5 on Apache (with SSL support), built on … 136 [OK]
eboraas/apache Apache (with SSL support), built on Debian 86 [OK]
webdevops/php-apache Apache with PHP-FPM (based on webdevops/php) 61 [OK]
webdevops/php-apache-dev PHP with Apache for Development (eg. with xd… 50 [OK]
tomee Apache TomEE is an all-Apache Java EE certif… 50 [OK]

[root@debasiseric3 ~]# docker search --filter stars=50 --filter is-official=true apache
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementati… 1802 [OK]
httpd The Apache HTTP Server Project 1634 [OK]
cassandra Apache Cassandra is an open-source distribut… 755 [OK]
maven Apache Maven is a software project managemen… 580 [OK]
solr Solr is the popular, blazing-fast, open sour… 518 [OK]
zookeeper Apache ZooKeeper is an open-source server wh… 353 [OK]
tomee Apache TomEE is an all-Apache Java EE certif… 50 [OK]




DOCKER CONCEPT FOR DBA – PART 6 Installation of docker UCP

This document will explain docker UCP for Enterprise grade cluster management

What is Docker UCP

Docker Universal Control Plane (UCP) is the enterprise-grade cluster management solution from Docker. You install it on-premises or in your virtual private cloud, and it helps you manage your Docker swarm and applications through a single interface.

Universal Control Plane is a containerized application that runs on Docker Enterprise Edition and extends its functionality to make it easier to deploy, configure, and monitor your applications at scale.

UCP also secures Docker with role-based access control so that only authorized users can make changes and deploy applications to your Docker cluster.

For more info , refer:-

https://docs.docker.com/datacenter/ucp/2.2/guides/architecture/

Installation of Docker UCP

Refer:-

https://docs.docker.com/datacenter/ucp/2.2/guides/admin/install/

Please note your private IP in case of cloud and you need to provide admin password

[user@debasiseric1 ~]$ docker container run --rm -it --name ucp -v /var/run/docker.sock:/var/run/docker.sock docker/ucp:2.2.4 install --host-address 172.31.96.15 --interactive

Unable to find image ‘docker/ucp:2.2.4’ locally

2.2.4: Pulling from docker/ucp

b56ae66c2937: Pull complete

68de5ce90bd1: Pull complete

d2de1fff8042: Pull complete

Digest: sha256:2b819b92d2209c0a5680fcee3f99c1090a9d4f1e6fea3003a9a661cbd16cc851

Status: Downloaded newer image for docker/ucp:2.2.4

INFO[0000] Verifying your system is compatible with UCP 2.2.4 (168ec746e)

INFO[0000] Your engine version 18.03.0-ce, build 0520e24 (3.10.0-693.21.1.el7.x86_64) is compatible

WARN[0000] Your system does not have enough memory.  UCP suggests a minimum of 2.00 GB, but you only have 1.88 GB.  You may have unexpected errors.

WARN[0002] Your system uses devicemapper.  We can not accurately detect available storage space.  Please make sure you have at least 3.00 GB available in /var/lib/docker

Admin Username: admin

Admin Password:

invalid: Admin Password – must be at least 8 characters

Admin Password:

Confirm Admin Password:

INFO[0038] Pulling required images… (this may take a while)

INFO[0038] Pulling docker/ucp-swarm:2.2.4

INFO[0039] Pulling docker/ucp-etcd:2.2.4

INFO[0040] Pulling docker/ucp-auth-store:2.2.4

INFO[0042] Pulling docker/ucp-compose:2.2.4

INFO[0044] Pulling docker/ucp-agent:2.2.4

INFO[0045] Pulling docker/ucp-cfssl:2.2.4

INFO[0046] Pulling docker/ucp-auth:2.2.4

INFO[0047] Pulling docker/ucp-metrics:2.2.4

INFO[0049] Pulling docker/ucp-hrm:2.2.4

INFO[0050] Pulling docker/ucp-controller:2.2.4

INFO[0052] Pulling docker/ucp-dsinfo:2.2.4

We detected the following hostnames/IP addresses for this system [debasiseric1.mylabserver.com 127.0.0.1 172.17.0.1 172.31.96.15]

You may enter additional aliases (SANs) now or press enter to proceed with the above list.

Additional aliases: ucp.example.com

INFO[0007] Establishing mutual Cluster Root CA with Swarm

INFO[0010] Installing UCP with host address 172.31.96.15 – If this is incorrect, please specify an alternative address with the ‘–host-address’ flag

INFO[0010] Generating UCP Client Root CA

INFO[0010] Deploying UCP Service

INFO[0042] Installation completed on debasiseric1.mylabserver.com (node qs8cyp1whprtfqikran65p1pj)

INFO[0046] Installation completed on debasiseric2.mylabserver.com (node rsux1r0yrm5uageho5wycrilk)

INFO[0046] UCP Instance ID: ykxn4szm49ny348z3z8ws4xpp

INFO[0046] UCP Server SSL: SHA-256 Fingerprint=62:9F:FB:1B:97:5C:2F:8E:6E:8A:F1:90:E7:18:0B:C6:EA:76:36:A4:A6:22:57:30:54:40:F7:2F:61:7F:29:0C

INFO[0046] Login to UCP at https://172.31.96.15:443

INFO[0046] Username: admin

INFO[0046] Password: (your admin password)

Login to docker UCP console now

Please login with admin user and password

Now you can get dash board

License Docker UCP now

Now that UCP is installed, you need to license it.

  1. Go to the Docker Store and buy a Docker EE subscription, or get a free trial license.
  2. In your browser, navigate to the UCP web UI, log in with your administrator credentials and upload your license. Navigate to the Admin Settings page and in the left pane, click License.

 

 

DOCKER CONCEPT FOR DBA– PART 5 Installation of Docker Swarm

What is a docker swarm?

A swarm consists of multiple Docker hosts which run in swarm mode and act as managers (to manage membership and delegation) and workers (which run swarm services). A given Docker host can be a manager, a worker, or perform both roles. When you create a service, you define its optimal state (number of replicas, network and storage resources available to it, ports the service exposes to the outside world, and more). Docker works to maintain that desired state. For instance, if a worker node becomes unavailable, Docker schedules that node’s tasks on other nodes. A task is a running container which is part of a swarm service and managed by a swarm manager, as opposed to a standalone container.

Installation of Docker Swarm

1.First identify IP of the host using below command

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001
inet 172.31.96.15 netmask 255.255.240.0 broadcast 172.31.111.255
inet6 fe80::102a:51ff:fee8:7188 prefixlen 64 scopeid 0x20<link>
ether 12:2a:51:e8:71:88 txqueuelen 1000 (Ethernet)
RX packets 52409 bytes 57532946 (54.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 15908 bytes 2546908 (2.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 3378 bytes 1144813 (1.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3378 bytes 1144813 (1.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

2.Please bind the Docker swarm with the IP

[root@debasiseric1 ~]# docker swarm init --advertise-addr 172.31.96.15

Swarm initialized: current node (qs8cyp1whprtfqikran65p1pj) is now a manager.

3.To add a worker to this swarm, run the following command:

[root@debasiseric1 ~]#docker swarm join-token worker

docker swarm join –token SWMTKN-1-69aokcgwacepwojdrepq25twysj3bptuea3lc2yn6ghfy5f478-bdjnimy0962cmth54vzcb0lu4 172.31.96.15:2377

4.To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.

[root@debasiseric1 ~]#docker swarm join-token manager

docker swarm join –token SWMTKN-1-69aokcgwacepwojdrepq25twysj3bptuea3lc2yn6ghfy5f478-bdjnimy0962cmth54vzcb0lu4 172.31.96.15:2377

5.Please check currently running docker engine

[root@debasiseric1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
qs8cyp1whprtfqikran65p1pj * debasiseric1.mylabserver.com Ready Active Leader 18.03.0-ce

6.Please check the managers and nodes running now

[root@debasiseric1 ~]#docker system info|more

Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 2
Server Version: 18.03.0-ce
Storage Driver: devicemapper
Pool Name: docker-202:1-50602726-pool
Pool Blocksize: 65.54kB
Base Device Size: 10.74GB
Backing Filesystem: xfs
Udev Sync Supported: true
Data file: /dev/loop0
Metadata file: /dev/loop1
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Data Space Used: 481.8MB
Data Space Total: 107.4GB
Data Space Available: 14.76GB
Metadata Space Used: 1.139MB
Metadata Space Total: 2.147GB
Metadata Space Available: 2.146GB
Thin Pool Minimum Free Space: 10.74GB
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Library Version: 1.02.140-RHEL7 (2017-05-03)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
NodeID: qs8cyp1whprtfqikran65p1pj
Is Manager: true
ClusterID: ykxn4szm49ny348z3z8ws4xpp
Managers: 1
Nodes: 1
Orchestration:

7.Now I will make 2nd node to join as worker

7.1 Install docker in 2nd node.Please follow below note:-

https://clouddba.co/docker-concept-part-1-concept-and-installation-of-docker-in-centos/

5.2 Configure docker in 2nd node

[root@debasiseric2 ~]# docker swarm join --token SWMTKN-1-69aokcgwacepwojdrepq25twysj3bptuea3lc2yn6ghfy5f478-bdjnimy0962cmth54vzcb0lu4 172.31.96.15:2377
This node joined a swarm as a worker.
[root@debasiseric2 ~]# docker node ls
Error response from daemon: This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager.
[root@debasiseric1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
qs8cyp1whprtfqikran65p1pj * debasiseric1.mylabserver.com Ready Active Leader 18.03.0-ce
rsux1r0yrm5uageho5wycrilk debasiseric2.mylabserver.com Ready Active 18.03.0-ce

8.Testing how Swarm works

8.1 Please create replica of 2 HTTPD instances to be running from different nodes of Docker

[root@debasiseric1 ~]# docker service create --name bkupweb --publish 80:80 --replicas 2 httpd

overall progress: 2 out of 2 tasks
1/2: running [==================================================>]
2/2: running [==================================================>]
verify: Service converged

8.2 Please check processes running for Docker

[root@debasiseric1 ~]# docker service ps bkupweb
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
2b6jegjjtpx9 bkupweb.1 httpd:latest debasiseric2.mylabserver.com Running Running 35 seconds ago
o4raa6qyt2ll bkupweb.2 httpd:latest debasiseric1.mylabserver.com Running Running 44 seconds ago

Docker concept for DBA- part 4 Install demo docker and test

Docker concept – part 4 Install demo docker and test

[user@debasiseric1 ~]$ sudo su –
[sudo] password for user:
Last login: Mon Apr 9 12:20:36 UTC 2018 on pts/0

[root@debasiseric1 ~]# cd /etc/docker

[root@debasiseric1 docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 6 70b5d81549ec 3 days ago 195MB

We need to pull the httpd demo docker image

[root@debasiseric1 docker]# docker image pull httpd
Using default tag: latest
latest: Pulling from library/httpd
f2b6b4884fc8: Pull complete
b58fe2a5c9f1: Pull complete
e797fea70c45: Pull complete
6c7b4723e810: Pull complete
02074013c987: Pull complete
4ad329af1f9e: Pull complete
0cc56b739fe0: Pull complete
Digest: sha256:b54c05d62f0af6759c0a9b53a9f124ea2ca7a631dd7b5730bca96a2245a34f9d
Status: Downloaded newer image for httpd:latest

Now you can check demo docker image httpd

[root@debasiseric1 docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 6 70b5d81549ec 3 days ago 195MB
httpd latest 805130e51ae9 2 weeks ago 178MB

[root@debasiseric1 docker]# docker container run -d –name testweb httpd
2d1d3bf7ad9479c5c21662d63f557849a15fa4b23c7dfd03a9a78afe647e3983

Please check IP address associated to this demo docker

[root@debasiseric1 docker]# docker container inspect testweb | grep IPAddr
“SecondaryIPAddresses”: null,
“IPAddress”: “172.17.0.2”,
“IPAddress”: “172.17.0.2”,

Please check what httpd processes are running

[root@debasiseric1 docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d1d3bf7ad94 httpd “httpd-foreground” 29 seconds ago Up 26 seconds 80/tcp testweb

[root@debasiseric1 docker]# sudo yum install -y telnet elinks

Please check whether your are able to connect to HTTP request using elinks

[root@debasiseric1 docker]# elinks http://172.17.0.2

docker concept for DBA-part-2 Run docker for non-privileged user (Other than root)

You need to change group to docker for user (non-privileged user) otherwise you get following error:-

[user@debasiseric1 ~]$ docker images
 Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.37/images/json: dial unix /var/run/docker.sock: connect: permission denied
Now I will login to root
sudo su -

cd /var/run

[root@debasiseric1 run]# ls -al docker.sock
 srw-rw---- 1 root docker 0 Apr 7 07:33 docker.sock
docker is the group which own docker.sock
[root@debasiseric1 run]# id -a user
 uid=1001(user) gid=1001(user) groups=1001(user),10(wheel)
Now add to the group to docker now
[root@debasiseric1 ~]# usermod -aG docker user

[root@debasiseric1 ~]# id -a user
 uid=1001(user) gid=1001(user) groups=1001(user),10(wheel),988(docker)
Now you will be able to run docker command from user
[user@debasiseric1 ~]$ docker images
 REPOSITORY TAG IMAGE ID CREATED SIZE

 

Docker concept -part 1-Concept and Installation of docker in CentOS

A. Basic Concept of docker

 

Docker is a platform for developers and sysadmins to develop, deploy, and run applications with containers. The use of Linux containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is.

Containerization is increasingly popular because containers are:

  • Flexible: Even the most complex applications can be containerized.
  • Lightweight: Containers leverage and share the host kernel.
  • Interchangeable: You can deploy updates and upgrades on-the-fly.
  • Portable: You can build locally, deploy to the cloud, and run anywhere.
  • Scalable: You can increase and automatically distribute container replicas.
  • Stackable: You can stack services vertically and on-the-fly.

 

Images and containers

A container is launched by running an image. An image is an executable package that includes everything needed to run an application–the code, a runtime, libraries, environment variables, and configuration files.

container is a runtime instance of an image–what the image becomes in memory when executed (that is, an image with state, or a user process). You can see a list of your running containers with the command, docker ps, just as you would in Linux.

Containers and virtual machines

container runs natively on Linux and shares the kernel of the host machine with other containers. It runs a discrete process, taking no more memory than any other executable, making it lightweight.

By contrast, a virtual machine (VM) runs a full-blown “guest” operating system with virtual access to host resources through a hypervisor. In general, VMs provide an environment with more resources than most applications need.

B.Installation of Docker

 

Step 1:-Let me install device mapper for docker

 

Device Mapper is a kernel-based framework that underpins many advanced volume management technologies on Linux. Docker’s devicemapper storage driver leverages the thin provisioning and snapshotting capabilities of this framework for image and container management. This article refers to the Device Mapper storage driver as devicemapper, and the kernel framework as Device Mapper.

For the systems where it is supported, devicemapper support is included in the Linux kernel. However, specific configuration is required to use it with Docker. For instance, on a stock installation of RHEL or CentOS, Docker defaults to overlay, which is not a supported configuration.

The devicemapper driver uses block devices dedicated to Docker and operates at the block level, rather than the file level. These devices can be extended by adding physical storage to your Docker host, and they perform better than using a filesystem at the level of the operating system.

[root@debasiseric1 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

Step 2:-Configure the repository for docker

 

[root@debasiseric1 ~]#yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@debasiseric1 ~]#yum update

step 3:-Installation of docker CE

 

[root@debasiseric1 ~]# yum install docker-ce

STEP 3:-Enable,start and check status of docker

 

[root@debasiseric1 ~]# systemctl enable docker
 [root@debasiseric1 ~]# systemctl start docker
 [root@debasiseric1 ~]# systemctl status docker
 ● docker.service - Docker Application Container Engine
 Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
 Active: active (running) since Sat 2018-04-07 07:33:47 UTC; 21s ago
 Docs: https://docs.docker.com
 Main PID: 2560 (dockerd)
 CGroup: /system.slice/docker.service
 ├─2560 /usr/bin/dockerd
 └─2564 docker-containerd --config /var/run/docker/containerd/containerd.toml

Apr 07 07:33:46 debasiseric1.mylabserver.com dockerd[2560]: time=”2018-04-07T07:33:46.343240219Z” level=info msg=”devmapper: Creating filesystem xfs on device docker-202:1-50602726-ba…2726-base]”
Apr 07 07:33:46 debasiseric1.mylabserver.com dockerd[2560]: time=”2018-04-07T07:33:46.453252654Z” level=info msg=”devmapper: Successfully created filesystem xfs on device docker-202:1…02726-base”
Apr 07 07:33:46 debasiseric1.mylabserver.com dockerd[2560]: time=”2018-04-07T07:33:46.642080401Z” level=info msg=”Graph migration to content-addressability took 0.00 seconds”
Apr 07 07:33:46 debasiseric1.mylabserver.com dockerd[2560]: time=”2018-04-07T07:33:46.642802165Z” level=info msg=”Loading containers: start.”
Apr 07 07:33:47 debasiseric1.mylabserver.com dockerd[2560]: time=”2018-04-07T07:33:47.185425888Z” level=info msg=”Default bridge (docker0) is assigned with an IP address 172.17.0.0/16…IP address”
Apr 07 07:33:47 debasiseric1.mylabserver.com dockerd[2560]: time=”2018-04-07T07:33:47.331338927Z” level=info msg=”Loading containers: done.”
Apr 07 07:33:47 debasiseric1.mylabserver.com dockerd[2560]: time=”2018-04-07T07:33:47.388427809Z” level=info msg=”Docker daemon” commit=0520e24 graphdriver(s)=devicemapper version=18.03.0-ce
Apr 07 07:33:47 debasiseric1.mylabserver.com dockerd[2560]: time=”2018-04-07T07:33:47.388608540Z” level=info msg=”Daemon has completed initialization”
Apr 07 07:33:47 debasiseric1.mylabserver.com dockerd[2560]: time=”2018-04-07T07:33:47.408123750Z” level=info msg=”API listen on /var/run/docker.sock”
Apr 07 07:33:47 debasiseric1.mylabserver.com systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

[root@debasiseric1 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE