[Docker] basic installation and architecture

Directory
- Centos7 installation Docker
- Docker architecture

1. CentOS7 installation Docker

Currently there are three branches of the docker, moby, docker-ce, docker-ee

moby is inherited from the former docker project is community-maintained open source project, anyone can create their own container products on the basis of moby.

docker docker-ce is to maintain the company's open source project, it is based on a free container products moby project

docker docker-ee is maintained by the company closed source products, docker's commercial products.

 

Here docker-ce mounted via yum on CentOS 7

[root@node1 ~]# uname -r 
3.10.0-327.el7.x86_64
[root@node1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

 Tsinghua yum source of information about the installation process docker-ce has been very clear: https://mirror.tuna.tsinghua.edu.cn/help/docker-ce/

 

 

 

Installation depends:
[root@node1 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

Download repo file:
[root@node1 ~]# wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo

Depot replaced by TUNA
[root@node1 ~]# sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

View docker-ce version:

 

 

Currently installed version: 19.03.3

[root@node1 ~]# yum install docker-ce -y

The installation is complete, start the service:
[root@node1 ~]# systemctl start docker

View docker information:

[root@node1 ~]# docker info

 

 

 

Run docker info warning message appears:

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

 Solution:

[root@node1 ~]# vim /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

[root@node1 ~]# sysctl -p

 Docker info run again

 

 

Alarm information: not recommended devicemapper storage drivers, it will be removed in a future release.

 

In version docker 19, the store is no longer recommended devicemapper drivers need to switch to overlayfs, what it is overlayfs?
First, overlayfs is a file system that is currently dokcer in the latest file system, the other file systems as well: aufs, device mapper and so on. In fact, while overlayfs and aufs are similar. More precisely, overlayfs, in fact, is one of the top Linux file system file system. The underlying file system format below, support overlayfs of:

  • ext4
  • xfs (xfs must be in the format of the time, specify -n ftype = 1, the use of the way if ftype = 1 in an unused formatted xfs file system, docker unknown error may occur)


How to view the current operating system supports overlay

[root@node1 ~]# lsmod | egrep overlay

If there is no output, it said they did not support, you can open the overlay by the following command

[root@node1 ~]# modprobe overlay

 

have to be aware of is:

  • docker official recommended overlay2, rather than the overlay, because overlay2 more efficient. To use overlay2 then need Linux kernel in version 4 or higher.
  • As long as the current operating system supports overlay, docker that you can use the overlay or overlay2.
  • Specifies the docker overlay2 drive, it is necessary to start docker when --storage-driver specified parameters, or, in the configuration file /etc/docker/daemon.json, the specified drive arrangement

 

What d_type xfs file system is

d_type is a term of the Linux kernel, which means "directory entry type", and directory entry is actually a data structure on the file system directory information. d_type, this field is a data structure, this field is used to indicate the type of the file, a file, or a pipe, or a directory or sockets and the like.

d_type from the beginning has been the Linux 2.6 kernel support, but although the Linux kernel, although support, but some file system to achieve d_type, while others, did not materialize, some are selective achieve, that is, require the user to use additional parameters decide whether to turn the support d_type.

Why docker need d_type in overlay2 (xfs file system)

Whether overlay, or overlay2, their underlying file system are overlayfs file system. The overlayfs file system will be used for file operations d_type this thing is being handled correctly. In other words, docker just use overlay or overlay2, is equivalent to using overlayfs, it will be used d_type.

docker info you docker service to detect whether when using the overlay of the correct use d_type. If the overlay / overlay2, but d_type not open, it reported a warning.

If you use a docker in d_typ does not support the overlay / overlay driven, which means docker when manipulating files, you may encounter some errors, such as certain directory or file can not be deleted, the file or directory permissions or user failure and many more. These are unexpected errors. For specific scene, that is, when the docker built, probably in the build process, delete files, and so failed, leading to stop building.

 

How to detect the current file system, support d_type?

 

 

Which ftype, 1 support d_type, 0 indicates no support.

 

So to deal with this error when installing the operating system will need to be prepared:

  • When the operating system is installed using the ext file system format
  • After the reservation partition formatting mount installation

.

 

Because there is a virtual machine by adding a disk to mount use, after formatting.

[root@node1 ~]# systemctl stop docker 
[root@node1 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0              11:0    1    4G  0 rom  /mnt/centos7
vda             252:0    0  100G  0 disk 
├─vda1          252:1    0  500M  0 part /boot
└─vda2          252:2    0 99.5G  0 part 
  ├─centos-root 253:0    0   50G  0 lvm  /
  ├─centos-swap 253:1    0  7.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 41.6G  0 lvm  /home
vdb             252:16   0   10G  0 disk

As used herein vdb partition and mount the file system as a docker.

Partition

[root@node1 ~]# fdisk /dev/vdb

format

 

 

Mounting

[root@node1 ~]# mount /dev/vdb1  /var/lib/docker

Start docker Service

[root@node1 ~]# systemctl start docker

 

 

Alert lifted, and start to change the default file overlay2 file system format.

 

Test docker run:

 

 

 

After the output of this prompt, hello world will stop running, the container is automatically terminated. Some containers are not automatically terminated because the service is provided, such as Mysql mirroring.

Docker provides a simple and practical commands to create and update a mirror, can be downloaded directly through the network has created a good image of the application, and by Docker RUN command can be used directly. After a successful run through the mirror RUN command, the operation of the mirror is a Docker container, the container can be understood as a lightweight sandbox, Docker use container to run applications and isolation, the container can be started, stopped, deleted, this does not affect Docker image.

 

 

 Docker Docker client is the primary way users interact with the Docker. When you use the command line to run the command docker, Docker client sends the commands to the server, the server will execute these commands. docker command docker API. Docker client can communicate with multiple server.

 

2. Docker architecture

Docker Chart

 

 

Docker's core components include:

  • Docker client
  • Docker daemon
  • Docker Image
  • Docker Registry
  • Docker Container

Docker uses a Client / Server architecture. The client sends a request to the server, which is responsible for building, operating and dispensing container. The client and server may run on the same Host, a client can also communicate with a remote socket or REST API server.

 

Docker Client

Docker Client, also known as the Docker client. It is actually Docker provides a command line interface (CLI) tool, is the primary way many users interact with Docker Docker. The client can build, run and stop applications, can also remotely interact with Docker_Host. The most commonly used Docker client is docker command, we can build and run through docker docker container easily command on the host.

 

Docker daemon

Docker daemon is the server components run as Linux daemon services, Docker is the core of the background process, we also call it the daemon. It is responsible for responding to requests from Docker Client, and then translate these requests into system calls to complete the container management operations. The process starts in the background a API Server, is responsible for receiving the request sent by Docker Client, received a request to distribute schedule a route through the interior of the Docker daemon to perform a specific function requested by.

 

Docker Image

Docker image can be seen as a special file system, in addition to providing the desired containers run programs, libraries, resources, configuration files, etc., but also contains a number of configuration parameters to prepare for the operation (such as anonymous volume, environment variables , users, etc.). Image does not contain any dynamic data, its contents will not be changed after the construct. We can Docker image as read-only templates, you can create a Docker container through it.

 

There are various image generation methods:

  • Start from scratch to create the mirror
  • Download and use someone else ready to create a good image
  • Create a new image on an existing image

 

Docker Registry

Docker registry docker Image storage warehouse, its location in the environment of docker shown below:

 

 Run docker push, docker pull, when docker search, registry actually communicate with docker daemon docker.

 

Docker Container

Docker Docker container is running instance of mirroring, is actually running the project program, local consumption of system resources to provide services. Docker Container provides system hardware environment, we can make good use of these Docker Images system disk, plus a good project our code, run it can provide service friends.

 

How Docker container component is run in collaboration

Container starts as follows:

 

 

Docker images can be viewed through the hello-world has been downloaded to the local

 

By docker ps or docker container ls display container is running, we can see, hello-world after the prompt information will stop running, the container is automatically terminated, so when viewed not found in container operation.

 

 

Run Docker containers collaboration components can be divided into the following processes:

  1. Docker client performs docker run the command
  2. Docker daemon found no local mirroring what we need
  3. daemon download the image from Docker Hub
  4. After the download is complete, the image is saved to the local
  5. Docker daemon start container

 

Docker commonly used commands

 

 

 

 

Reference links:

https://www.jianshu.com/p/00ffd8df6010

Guess you like

Origin www.cnblogs.com/hukey/p/11656096.html