Docker


Here’ s flag: i will take down all the notes concerning Docker in English while going through training courses from Udemy site . Not as difficult as some people may think .
I really was good at English a few years ago.Perhaps it 's a great chance to pick it up and get it refreshed .

1、Why Docker?

Simply , to make it easy to install softwares not worrying about setup and dependices.
Say,you can’t install a Redis server on a Mac by ‘wget’ it from remoting,since ‘wget’ is a
Linux cmd.
Wow,you have to identify cmd adapted to Mac before you do install a Redis.That’s a trouble .

2、What’s Docker?

Look at the first pic.
When people say ‘i use Docker’ ,what on earth are they talk about .
Docker means an entire ecosystem ,and it’s not simply a specific software.
Docker

First of all ,here are two core concepts,namely , images and containers.

  • Images : a single file
  • Containers: an instance of image. Just think of it as a program with its own isolated set of hardware resources, memory, networking,hard drive,etc.
    A container’s sole purpose is to run one very specific program so the Docker server then essentially takes that single file,loads it up into memory ,creates a container out of it,and then runs a single program inside.
    Docker

3、Docker on your OS

It’s a big issue that you tell the difference between Docker client(also named as Docker Cli) and Docker Server( also Docker Daemon).

In the Linux world ,Daemon means the specific program that runs the service.NOT necessary to isolate them from each other ,just treat them as the same thing.
Docker
We now comes to the right point.How do we install an Docker.
Click https://www.docker.com/get-started for detailed steps,and i am not going to describe it here.
But you’d better know that Docker Desktop for Windows runs OK both on linux and Windows.Just checkout it out on this website.

4、Hello-world

After you give a cmd of ‘Docker run hello-world’ ,Docker do four steps:

  1. the Docker Cli receives the cmd ,and issues it to the Docker Server
  2. Docker Server looks for the ‘hello-world’ image in the local cache. Image is a file,as i described just now.
  3. Since it’s the first time we run the cmd, the image cache ,certainly ,is empty.Then Docker server contacts the Docker Hub for a ‘hello-worl’ docker image (file).
  4. Of course,the Docker Hub has got the docker image ,and it passes the file to Dokcer Server .Server saves the file into the cache,and downloads the software as configurated in the file.
    Docker

5、What the Container is

We answer this question in this scene:
Provided that you run chrome that needs Python V2 ,and you run NodeJS that needs Python3.However ,you only have Python2 on your hard drive.Now ,your NodeJS may not properly function .
What would you do to tackle this embarrasing problem?
Docker comes up with a good idea based on a crux named ‘Name Spacing’.This technique segments hard drive into pieces.If Chrome calls,the kernel directs that call over to the according little segment ,and it works for NodeJS as well.So ‘Name Spacing’, kind of some mechanism to isloate resources.
Docker
**Addtionally, NameSpacing can also be applied to Software,not merely Hardware.**Technically, the flow above only describes how it functions on hard disk.Now ,the charts below illustrates the software side.

  • In these charts,NameSpacing isolate resources per prorcess,or group of processes.
    For example,we can namespace a process to restrict the area of a hard drive that is available or the network devices that are available, etc.(即:利用“name spacing” 限定了进程所能利用的 软、硬件资源。
  • A very close concept is Control Groups(Cgroups),cgroups limit the amount of resources that a particular process can use.

Docker
Namespacing and cgroups together make it possible to isolate resources and take processes under controll.

Now come back to the point.What is the container?
The given area within the dashed line box tells us what it is .Container is not a physical construct .Instead ,a container is really a set of processes that have a grouping of resources specifically assinged to it.To make it clear , i think you should look and see another pic down there .
Docker

Docker

So ,now ,what is the relationship between a container and an image.Fine,just look at this diagram.
An image is technically a FS snapshot ,with a startup cmd.
Docker

6、How Docker runs on Mac or Windows

Namespcing ,and cgroups are only specific to Linux OS ,but Docker runs well on a Mac or Windows.How does it make it ?
Well, when we install a Docker on a PC or Mac ,we also install a Linux Virtual Machine,which behaves as the host of running processes.
You can confirm it as you input ‘docker version’ on your OS ,and look at the ‘Server’ section.Basically,it reads ’ Linux’! That’ pretty much it.
Docker