preface

Welcome to our GitHub repository Star: github.com/bin39232820… The best time to plant a tree was ten years ago, followed by now. I know many people don’t play QQ anymore, but for a moment of nostalgia, welcome to join the six-vein Shenjian Java rookie learning group, group chat number: 549684836 encourage everyone to write blog on the road of technology

omg

Many friends asked me to write down Docker. I know how to use Docker myself, so I didn’t go into the bottom layer and felt there was nothing to write down. But today, our boss asked us to study ClickHouse, and when I checked the information, there was a way to install Docker. But I found that the company server did not install Docker, SO I installed it and wrote an article, haha. In fact, it is also for the future use of direct use.

What is a Docker

Docker is an internal project initiated by dotCloud founder Solomon Hykes while he was in France. It is based on dotCloud’s innovation of cloud service technology for many years, and opened source under Apache 2.0 license in March 2013. The main project code is maintained on GitHub. The Docker project later joined the Linux Foundation and formed the Alliance for Advancing Open Containers (OCI).

Docker’s GitHub project has more than 46,000 stars and more than 10,000 forks. DotCloud even decided to change its name to Docker at the end of 2013 due to the popularity of the Docker project. Docker was originally developed and implemented on Ubuntu 12.04; Red Hat has supported Docker since RHEL 6.5. Google also uses Docker extensively in its PaaS products.

Docker uses Go language launched by Google for development and implementation, and is based on cgroup, Namespace of Linux kernel and Union FS of AUFS class to encapsulate and isolate processes, which is a virtualization technology at the level of operating system. Since a quarantined process is independent of the host and other quarantined processes, it is also called a container. The initial implementation was based on LXC, which was removed after version 0.7 in favor of home-grown libContainer, and has evolved to use runC and Containerd since 1.11.

Docker has further encapsulation on the basis of containers, from file system, network interconnection to process isolation and so on, which greatly simplifies the creation and maintenance of containers. Docker technology is lighter and faster than virtual machine technology.

The following image compares Docker with traditional virtualization. The traditional virtual machine technology is to create a set of virtual hardware, run a complete operating system on it, and then run required application processes on the system. The application process in the container runs directly on the host kernel, without its own kernel and without hardware virtualization. Therefore, containers are much lighter than traditional virtual machines.

Why Docker

As an emerging virtualization method, Docker has many advantages over traditional virtualization methods

  • More efficient use of system resources
  • Faster startup time
  • Consistent operating environment
  • Continuous delivery and deployment
  • Easier migration
  • Compare with traditional virtual machines

Docker mirror

As we all know, operating systems are divided into kernel and user space. For Linux, the root file system is mounted to provide user-space support after the kernel is started. A Docker Image, on the other hand, is a root file system. For example, the official ubuntu:16.04 image contains a complete set of root file systems for the ubuntu 16.04 minimum system.

Docker image is a special file system, in addition to providing programs, libraries, resources, configuration files required by the container runtime, but also contains some configuration parameters prepared for the runtime (such as anonymous volumes, environment variables, users, etc.). The image does not contain any dynamic data and its contents are not changed after the build.

A hierarchical

Because the image contains the complete root file system of the operating system, and its volume is often huge, Docker made full use of the technology of Union FS to design it as a layered storage architecture. So, strictly speaking, an image is not a packaged file like an ISO. An image is a virtual concept whose actual embodiment is not a file but a group of file systems, or a combination of multiple file systems.

When a mirror is built, one layer is built on top of the other. After each layer is built, there are no more changes, and any changes on the next layer only happen on your own layer. For example, deleting a file at the previous layer does not actually delete the file at the previous layer, but only marks the file as deleted at the current layer. This file will not be seen when the final container runs, but it will actually follow the image. Therefore, when building the image, extra care should be taken. Each layer should contain only what needs to be added to that layer, and any extras should be cleared away before the layer is built.

The feature of hierarchical storage also makes it easier to reuse and customize images. You can even use the previously built image as the base layer and then add new layers to customize what you need to build new images.

Docker container

The relationship between an Image and a Container is similar to that between a class and an instance in object-oriented programming. An Image is a static definition and a Container is an entity of the Image runtime. Containers can be created, started, stopped, deleted, paused, and so on.

The essence of a container is a process, but unlike processes that execute directly on the host, container processes run in their own separate namespace. So a container can have its own root file system, its own network configuration, its own process space, and even its own user ID space. The processes inside the container run in an isolated environment and are used as if they were operating on a separate system from the host. This feature makes container-wrapped applications more secure than running directly on the host. Because of this isolation, many newcomers to Docker often confuse containers with virtual machines.

As mentioned earlier, images use tiered storage, as do containers. Each container runtime is based on an image, on which a storage layer of the current container is created. We can call this storage layer prepared for the container runtime reads and writes the container storage layer.

The container storage layer lives the same as the container. When the container dies, the container storage layer dies with it. Therefore, any information stored in the container storage layer is lost when the container is deleted.

As per Docker best practices, containers should not write any data to their storage layer, and the container storage layer should remain stateless. All file writing operations should use data volumes or bind host directories. Read/write operations in these locations skip the container storage layer and directly read/write operations to the host (or network storage), achieving higher performance and stability.

The lifetime of a data volume is independent of the container. The container dies and the data volume does not die. Therefore, after using data volumes, the container is deleted or re-run without data loss.

The Docker warehouse

After the image is built, it can be easily run on the current host. However, if the image needs to be used on other servers, we need a centralized service to store and distribute the image, and Docker Registry is such a service.

A Docker Registry can contain multiple repositories. Each repository can contain multiple tags; Each label corresponds to a mirror.

Typically, a repository contains images of different versions of the same software, and labels are often used to match versions of the software. We can specify which version of this software is the mirror by using the format < repository >:< tag >. If no label is given, latest is used as the default label.

Take the Ubuntu image as an example. Ubuntu is the name of the repository, which contains different version tags such as 14.04 and 16.04. Ubuntu :14.04 or Ubuntu :16.04 can be used to specify which version of the image is required. If you omit the tag, such as Ubuntu, it will be treated as Ubuntu: Latest.

The repository name is often presented as a two-step path, such as Jwilder /nginx-proxy, which tends to mean the user name in a Docker Registry multi-user environment and the corresponding software name. This is not absolute, however, depending on the specific Docker Registry software or service being used

Install Docker (centos7)

Docker requires a CentOS kernel version later than 3.10. Check the prerequisites on this page to verify whether your CentOS version supports Docker.

Check your current kernel version with the uname -r command

 $ uname -r
Copy the code

2. Log in to Centos as user root. Make sure the YUM package is up to date.

$ sudo yum update
Copy the code

3. Uninstall the old version (if any)

$ sudo yum remove docker  docker-common docker-selinux docker-engine
Copy the code

Yum-util provides yum-config-manager functionality. The other two are dependent on devicemapper drivers

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Copy the code

5. Configure the yum source

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Copy the code

6. You can view all docker versions in all warehouses and select a specific version to install

$ yum list docker-ce --showduplicates | sort -r
Copy the code

7. Install Docker

# $sudo yum install docker-ce # $sudo yum install <FQPN> # Sudo yum install docker - ce - 17.12.0. CeCopy the code

8. Start and join boot

$ sudo systemctl start docker
$ sudo systemctl enable docker
Copy the code

9, verify whether the installation is successful (there are two parts of client and service, indicating that docker installation and startup are successful)

$ docker version
Copy the code

For a system using systemd, please write the following contents in /etc/dock/daemon. json (if the file does not exist, please create a new file).

{
  "registry-mirrors": [
    "https://registry.docker-cn.com"
  ]
}
Copy the code

Then restart the service.

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
Copy the code

At the end

Today, I will introduce the installation of docker. I have referred to other people’s articles, but this installation process is tested by myself

  • www.cnblogs.com/yufeng218/p…

Daily for praise

Ok, everybody, that’s all for this article, you can see people here, they are real fans.

Creation is not easy, your support and recognition, is the biggest motivation for my creation, we will see in the next article

Six pulse excalibur | article “original” if there are any errors in this blog, please give criticisms, be obliged!