Your First Docker installation.

The Dockers are now known as containers which ofcourse have eveolved from their previous ancestor Containers.

There have also been many predictions that the Docker is the Future and the harbor of Innovation.

The containers are known to be a micro instance of realtime running OS running within a linux/unix OS.

The containers provide a secure isolated evnvironment for the applications to live in base os’s run time environment.

But not to be confused it with Virtualmachines which also appear they are running on top of an OS.

But first we need to note that the Docker uses a special typical filesystem call union filesystem, which joins the individual layers with in the container to present a persistent filesystem.

The key factors that docker containers has maximum attention is the they consume lesser CPU, RAM and disk resources than that of the Virtual Machines which ofcourse cuts down a overhead on the host os.
The installation of docker is just as easy just, you pull off the latest version of docker from your package manager
Ensure you have sudo access
On Ubuntu

[root@Arch-DOC ~]# sudo apt-get update

[root@Arch-DOC ~]# apt-get install docker.io

The containers consists of Layers which are formed by a build instruction.

Once the installation is done.

Ensure the docker service is started and startup is enabled.
[root@Arch-DOC ~]# systemctl status docker
‚óŹ docker.service – Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://docs.docker.com
[root@Arch-DOC ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@Arch-DOC ~]# systemctl start docker

Now the Docker daemon is started, On a fresh install there will not be any images pre bundled.

With the user of docker search <container name> you can always catchup and search for some cool images out in from the public repository created by other users.
[root@Arch-DOC ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 3064 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker c… 648 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable … 195 [OK] million12/nginx-php Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS… 63 [OK] maxexcloo/nginx-php Docker framework container with Nginx and … 57 [OK] webdevops/php-nginx Nginx with PHP-FPM 31 [OK] h3nrik/nginx-ldap NGINX web server with LDAP/AD, SSL and pro… 27 [OK] bitnami/nginx Bitnami nginx Docker Image 18 [OK] maxexcloo/nginx Docker framework container with Nginx inst… 7 [OK] million12/nginx Nginx: extensible, nicely tuned for better… 4 [OK] ixbox/nginx Nginx on Alpine Linux. 3 [OK] webdevops/nginx Nginx container 3 [OK] evild/alpine-nginx Minimalistic Docker image with Nginx 3 [OK] drupaldocker/nginx NGINX for Drupal 2 [OK] 1science/nginx Nginx Docker images based on Alpine Linux 2 [OK] dock0/nginx Arch container running nginx 2 [OK] xataz/nginx Light nginx image 2 [OK] yfix/nginx Yfix own build of the nginx-extras package 2 [OK] radial/nginx Spoke container for Nginx, a high performa… 1 [OK] servivum/nginx Nginx Docker Image with Useful Tools 1 [OK] blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 1 [OK] unblibraries/nginx Baseline non-PHP nginx container 0 [OK] tozd/nginx Dockerized nginx. 0 [OK] c4tech/nginx Several nginx images for web applications. 0 [OK] datenbetrieb/nginx nginx docker image based on debian 0 [OK]

Now lets start off with downloading a small docker image, like hello-world, which has a simple script which prints out Hello message onto the standard output.

[root@Arch-DOC ~]# docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
4276590986f6: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:4f32210e234b4ad5cac92efacc0a3d602b02476c754f13d517e1ada048e5a8ba
Status: Downloaded newer image for hello-world:latest

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.
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 Hub account:
https://hub.docker.com

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

We can see the hello-world image that we downloaded as follows:
[root@Arch-DOC ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 94df4f0ce8a4 4 weeks ago 967 B

[root@Arch-DOC ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0d0f9d724810 hello-world “/hello” 6 seconds ago Exited (0) 4 seconds ago goofy_ardinghelli

The ps -a command lists the running and previously exited containers, As now we can see that our container hello-world has exited very recently, It has automatically been tagged with random NAME<goofy_ardinghelli>, we can also specify our own name using the option –name=<Your_Name>

The status flags can be appended and queried to check the status of the running instances.

[root@Arch-DOC ~]# docker ps -a -f status=exited
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0d0f9d724810 hello-world “/hello” 7 minutes ago Exited (0) 7 minutes ago goofy_ardinghelli

The image can be fetched and any number of containers can be spawned from it.
Some examples of the prebuild images can be found from the public resository

[root@Arch-DOC ~]# docker search cisco
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ciscocloud/mesos-consul 10 [OK] ciscocloud/marathon-consul 6 [OK] ciscocloud/nginx-consul 3 [OK]

Not just that, One can even run a virtually real environment like ubuntu/Centos/Redhat/Solaris and any other environment with a docker image of merely 200-300 MB

Here I have downloaded a light footprint image called Busybox, and have turned on the interactive

[root@Arch-DOC ~]# docker run -it busybox
Unable to find image ‘busybox:latest’ locally
latest: Pulling from library/busybox
385e281300cc: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:4a887a2326ec9e0fa90cce7b4764b0e627b5d6afcb81a3f73c85dc29cea00048
Status: Downloaded newer image for busybox:latest
/ # hostname
c90384b5463e

The container gets a hostname identical to the first few characters of its CONTAINER ID

/ # pwd
/
/ # ls
bin dev etc home proc root sys tmp usr var
/ # ls -lth
total 12
drwxr-xr-x 2 root root 26 May 28 12:59 root
drwxr-xr-x 5 root root 380 May 28 12:59 dev
dr-xr-xr-x 242 root root 0 May 28 12:59 proc
drwxr-xr-x 2 root root 124 May 28 12:59 etc
dr-xr-xr-x 13 root root 0 May 28 05:21 sys
drwxr-xr-x 2 root root 8.0K Mar 18 16:39 bin
drwxr-xr-x 3 root root 18 Mar 18 16:39 usr
drwxr-xr-x 4 root root 30 Mar 18 16:39 var
drwxr-xr-x 2 nobody nogroup 6 Mar 18 16:38 home
drwxrwxrwt 2 root root 6 Mar 18 16:38 tmp
/ # uname -a
Linux c90384b5463e 4.5.4-1-ARCH #1 SMP PREEMPT Wed May 11 22:21:28 CEST 2016 x86_64 GNU/Linux
/ # exit

exit brings you back to the host os.

Now you can see the tiny footprint of it
root@Arch-DOC ~]# docker images –no-trunc busybox
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest sha256:47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb 10 weeks ago 1.113 MB

Similarly you can see the size of ubuntu:16.04 size is 120MB.
root@Arch-DOC ~]# docker images –no-trunc ubuntu
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 686477c129822fe596331ebdd2f7ba6d2e4a8e90132c2388313b921e547a9112 3 weeks ago 120.8 MB
There is also another way to start and connect to the running container

[root@Arch-DOC ~]# docker start evil_yalow
evil_yalow
[root@Arch-DOC ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c90384b5463e busybox “sh” 23 minutes ago Up 2 seconds evil_yalow

Wish the attach option we can connect to the container
[root@Arch-DOC ~]# docker attach evil_yalow
/ #

Within the container, ou can issue the normal linux commands available in the linux ecosystem.

[root@Arch-DOC ~]# docker attach evil_yalow
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:648 (648.0 B) TX bytes:648 (648.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/ # exit

[root@Arch-DOC ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c90384b5463e busybox “sh” 4 minutes ago Exited (0) 43 seconds ago evil_yalow
0d0f9d724810 hello-world “/hello” 14 minutes ago Exited (0) 14 minutes ago goofy_ardinghelli

And finally to clean up and remove the containers, with docker rm <container ID> which completely removes them

[root@Arch-DOC ~]# docker rm goofy_ardinghelli
goofy_ardinghelli

root@Arch-DOC ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c90384b5463e busybox “sh” 5 minutes ago Exited (0) About a minute ago evil_yalow

The images can be removed with the rmi option

[root@Arch-DOC ~]# docker rmi hello-world:latest
Untagged: hello-world:latest
Deleted: sha256:94df4f0ce8a4d4d4c030b9bdfe91fc9cf6a4b7be914542315ef93a046d520614
Deleted: sha256:92953e7618fbb0f7991146fccf4da3dc31e1b5104b6d6c9572ee75d3eba240a2
Deleted: sha256:33e7801ac047e45517f22927037407c9753aa27ed72a5932c3e0886477041b12
The netowrking in docker works because of bridging, the host os caters this feature and a bridge interface docker0 is created

[root@Arch-DOC ~]# ifconfig docker0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:64ff:fe2d:253f prefixlen 64 scopeid 0x20<link>
ether 02:42:64:2d:25:3f txqueuelen 0 (Ethernet)
RX packets 10 bytes 688 (688.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 686 (686.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@Arch-DOC ~]# docker network ls
NETWORK ID NAME DRIVER
18a34172a238 bridge bridge
818e3d58d57d host host
d1b6dabf54f9 none null
You can also explore the environment with docker inspect, suggest you to try out this option.
[root@Arch-DOC ~]# docker inspect busybox

Also just a fact of the matter, the whole docker information is stored on the base system in the form of json, and we can even try to fetch some of the details by entering /var/lib/docker/
cat /var/lib/docker/image/devicemapper/repositories.json
{“Repositories”:{“busybox”:{“busybox:latest”:”sha256:47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb”},”hello-world”:{“hello-world:latest”:”sha256:94df4f0ce8a4d4d4c030b9bdfe91fc9cf6a4b7be914542315ef93a046d520614″}}}
So thats all for now, next we’ll explore about and building custom containers.

About the author

Vamshi S

Leave a Comment