Skip to content

Commit b9cb30b

Browse files
committed
Add docker container documentation
1 parent 516b4dc commit b9cb30b

File tree

1 file changed

+113
-2
lines changed

1 file changed

+113
-2
lines changed

docs/Understanding-Containers.md

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,113 @@
1-
# Understanding containers
2-
Content coming soon.
1+
# Let’s begin by understanding, What is Docker?
2+
3+
In simple terms, Docker is a software platform that simplifies the process of building, running,
4+
managing and distributing applications. It does this by virtualizing the operating system of the
5+
computer on which it is installed and running.
6+
7+
# The Problem
8+
Let’s say you have three different Python-based applications that you plan to host on a single server
9+
(which could either be a physical or a virtual machine).
10+
11+
Each of these applications makes use of a different version of Python, as well as the associated
12+
libraries and dependencies, differ from one application to another.
13+
14+
Since we cannot have different versions of Python installed on the same machine, this prevents us from
15+
hosting all three applications on the same computer.
16+
17+
# The Solution
18+
Let’s look at how we could solve this problem without making use of Docker. In such a scenario, we
19+
could solve this problem either by having three physical machines, or a single physical machine, which
20+
is powerful enough to host and run three virtual machines on it.
21+
22+
Both the options would allow us to install different versions of Python on each of these machines,
23+
along with their associated dependencies.
24+
25+
The machine on which Docker is installed and running is usually referred to as a Docker Host or Host in
26+
simple terms. So, whenever you plan to deploy an application on the host, it would create a logical
27+
entity on it to host that application. In Docker terminology, we call this logical entity a Container or
28+
Docker Container to be more precise.
29+
30+
Whereas the kernel of the host’s operating system is shared across all the containers that are running
31+
on it.
32+
33+
This allows each container to be isolated from the other present on the same host. Thus it supports
34+
multiple containers with different application requirements and dependencies to run on the same host,
35+
as long as they have the same operating system requirements.
36+
37+
# Docker Terminology
38+
39+
Docker Images and Docker Containers are the two essential things that you will come across daily while
40+
working with Docker.
41+
42+
In simple terms, a Docker Image is a template that contains the application, and all the dependencies
43+
required to run that application on Docker.
44+
45+
On the other hand, as stated earlier, a Docker Container is a logical entity. In more precise terms,
46+
it is a running instance of the Docker Image.
47+
48+
# What is Docker-Compose?
49+
50+
Docker Compose provides a way to orchestrate multiple containers that work together. Docker compose
51+
is a simple yet powerful tool that is used to run multiple containers as a single service.
52+
For example, suppose you have an application which requires Mqtt as a communication service between IOT devices
53+
and OpenHAB instance as a Smarthome application service. In this case by docker-compose, you can create one
54+
single file (docker-compose.yml) which will create both the containers as a single service without starting
55+
each separately. It wires up the networks (literally), mounts all volumes and exposes the ports.
56+
57+
The IOTstack with the templates and menu is a generator for that docker-compose service descriptor.
58+
59+
# How Docker Compose Works?
60+
61+
use yaml files to configure application services (docker-compose.yaml)
62+
can start all the services with a single command ( docker-compose up )
63+
can stop all the service with a single command ( docker-compose down )
64+
65+
# How are the containers connected
66+
The containers are automagically connected when we run the stack with docker-compose up.
67+
The containers using same logical network (by default) where the instances can access each other with the instance
68+
logical name. Means if there is an instance called *mosquitto* and an *openhab*, when openHAB instance need
69+
to access mqtt on that case the domain name of mosquitto will be resolved as the runnuning instance of mosquitto.
70+
71+
# How the container are connected to host machine
72+
73+
## Volumes
74+
75+
The containers are enclosed processes which state are lost with the restart of container. To be able to
76+
persist states volumes (images or directories) can be used to share data with the host.
77+
Which means if you need to persist some database, configuration or any state you have to bind volumes where the
78+
running service inside the container will write files to that binded volume.
79+
In order to understand what a Docker volume is, we first need to be clear about how the filesystem normally works
80+
in Docker. Docker images are stored as series of read-only layers. When we start a container, Docker takes
81+
the read-only image and adds a read-write layer on top. If the running container modifies an existing file,
82+
the file is copied out of the underlying read-only layer and into the top-most read-write layer where the
83+
changes are applied. The version in the read-write layer hides the underlying file, but does not
84+
destroy it -- it still exists in the underlying layer. When a Docker container is deleted,
85+
relaunching the image will start a fresh container without any of the changes made in the previously
86+
running container -- those changes are lost, thats the reason that configs, databases are not persisted,
87+
88+
Volumes are the preferred mechanism for persisting data generated by and used by Docker containers.
89+
While bind mounts are dependent on the directory structure of the host machine, volumes are completely
90+
managed by Docker. In IOTstack project uses the volumes directory in general to bind these container volumes.
91+
92+
## Ports
93+
When containers running a we would like to delegate some services to the outside world, for example
94+
OpenHAB web frontend have to be accessible for users. There are several ways to achive that. One is
95+
mounting the port to the most machine, this called port binding. On that case service will have a dedicated
96+
port which can be accessed, one drawback is one host port can be used one serice only. Another way is reverse proxy.
97+
The term reverse proxy (or Load Balancer in some terminology) is normally applied to a service that sits in front
98+
of one or more servers (in our case containers), accepting requests from clients for resources located on the
99+
server(s). From the client point of view, the reverse proxy appears to be the web server and so is
100+
totally transparent to the remote user. Which means several service can share same port the server
101+
will route the request by the URL (virtual domain or context path). For example, there is *grafana* and *openHAB*
102+
instances, where the *opeanhab.domain.tld* request will be routed to openHAB instance 8181 port while
103+
*grafana.domain.tld* to grafana instance 3000 port. On that case the proxy have to be mapped for host port 80 and/or
104+
444 on host machine, the proxy server will access the containers via the docker virtual network.
105+
106+
107+
Source materials used:
108+
109+
https://takacsmark.com/docker-compose-tutorial-beginners-by-example-basics/
110+
https://www.freecodecamp.org/news/docker-simplified-96639a35ff36/
111+
https://www.cloudflare.com/learning/cdn/glossary/reverse-proxy/
112+
https://blog.container-solutions.com/understanding-volumes-docker
113+

0 commit comments

Comments
 (0)