Docker (1) ----Initial Docker


Preface

This article is mainly a summary of Dark Horse’s Docker course.


1. What is Docker

1.1 Definition of Docker

Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable image, and then publish it to any popular Linux or Windows operating system machine, which can also be virtualized. Containers completely use the sandbox mechanism and will not have any interfaces with each other.

In normal development, large projects rely on many components and the operating environment is more complex, and some problems may be encountered during deployment.

  • Dependencies are complex and compatibility issues are prone to occur
  • Development, testing, and production environments are different

Please add image description

1.2 Docker’s solution to the above problems

Dependency compatibility issues:

  • Package the application's Libs (function library), Deps (dependencies), and configuration together with the application

  • Put each application into an isolated container to run to avoid mutual interference.
    Please add image description
    The operating systems of different environments are different. How does Docker solve this problem? At this time we need to understand the basic structure of the operating system:
    Please add image description

  • The kernel interacts with the hardware and provides instructions for operating the hardware

  • System applications encapsulate kernel instructions as functions, making it easier for programmers to call

  • The user program implements functions based on the function library

Different system environment issues

Please add image description

The above content can be summarized as follows

How does Docker solve the compatibility issues of complex dependencies and dependencies on different components in large projects?

  • Docker allows applications, dependencies, function libraries, and configurations to be packaged together during development to form a portable image.
  • Docker applications run in containers and are isolated from each other using a sandbox mechanism.

How Docker solves the problem of differences between development, testing, and production environments

  • The Docker image contains a complete operating environment, including function libraries, and only relies on the Linux kernel, so it can run on any Linux operating system

Docker is a technology for quickly delivering and running applications:

  1. The program, its dependencies, and the operating environment can be packaged together into an image, which can be migrated to any Linux operating system
  2. The sandbox mechanism is used to form an isolated container during runtime, so that each application does not interfere with each other.
  3. Startup and removal can be completed with one line of commands, which is convenient and fast

2. Docker and virtual machines

Please add image description

The difference between Docker and virtual machines

  • docker is a system process; a virtual machine is an operating system running in the operating system
  • Docker is small in size, fast in startup, and has good performance; virtual machine is large in size and slow in startup.
    Please add image description

3. Docker architecture

Before understanding the Docker architecture, let's first look at a few basic concepts.

3.1 Images and containers

Image: Docker packages the application and its required dependencies, function libraries, environment, and configuration files together, called an image.

Container: The process formed after running the application in the image is the container, but Docker will isolate the container and make it invisible to the outside world.
Please add image description

3.2 Docker and Docker Hub

  • DockerHub: DockerHub is a hosting platform for Docker images. This platform is called Docker Registry. The official address is: https://hub.docker.com/
  • There are also public services similar to DockerHub in China, such as NetEase Cloud Image Service, Alibaba Cloud Image Library , etc.Please add image description

3.3 Docker architecture

Docker is a CS architecture program consisting of two parts:

  • Server: Docker daemon, responsible for processing Docker instructions, managing images, containers, etc.
  • Client: Send instructions to the Docker service through commands or RestAPI. Instructions can be sent to the server locally or remotely
    Please add image description

summary

Image: Package the application, dependencies, environment, and configuration together.
Container: When the image is run, it is a container. One image can run multiple containers.
Dokcer structure:

  • Server: receives commands or remote requests, operates images or containers
  • Client: Send commands or requests to the Docker server

DockerHub: An image hosting server, similar to Alibaba Cloud Image Service, collectively called DockerRegistry

4. Install Docker

Docker is divided into two major versions: CE and EE. CE is the community edition (free, support period is 7 months), EE is the enterprise edition, which emphasizes security, is paid for use, and has a support period of 24 months.

Docker CE is divided into three update channels: stable testand .nightly

The official website has installation guides for various environments . Here we mainly introduce the installation of Docker CE on CentOS.

4.1 Uninstall (optional)

Docker CE supports the 64-bit version of CentOS 7, and requires the kernel version to be no less than 3.10. CentOS 7 meets the minimum kernel requirements, so we install Docker on CentOS 7.

If you have installed an older version of Docker before, you can uninstall it using the following command: (\ here represents a newline)

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine \
                  docker-ce

4.2 Install Docker

First, everyone needs to connect the virtual machine to the Internet and install the yum tool.

yum install -y yum-utils \
           device-mapper-persistent-data \
           lvm2 --skip-broken

Then update the local mirror source

# 设置docker镜像源
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

yum makecache fast

Then enter the command:

yum install -y docker-ce

docker-ce is a community free version. Wait a moment and docker will be installed successfully.

4.3 Start Docker

Docker applications need to use various ports and modify the firewall settings one by one. It’s very troublesome, so I suggest you turn off the firewall directly!

# 关闭
systemctl stop firewalld
# 禁止开机启动防火墙
systemctl disable firewalld

Start docker via command

systemctl start docker  # 启动docker服务

systemctl stop docker  # 停止docker服务

systemctl restart docker  # 重启docker服务

Then enter the command to view the docker version:

docker -v

Insert image description here

4.4 Configure image acceleration

The Internet speed of docker's official image warehouse is poor. We need to set up a domestic image service:

Refer to Alibaba Cloud's mirror acceleration documentation: https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
Insert image description here

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://erkkyc68.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Summarize

The above is the complete initial explanation of Docker. I hope you can understand the basic definition of Docker, why to use Docker, the architecture of Docker and how to install Docker. If you have any questions, you can discuss them in the comment area.

Guess you like

Origin blog.csdn.net/TheWindOfSon/article/details/128194670
Recommended