Docker super detailed installation tutorial and underlying principles, an article to help you understand what is Docker

Docker overview

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, and can also implement virtualization. Containers use a sandbox mechanism completely, and there will be no interfaces between them.

Essence: All technologies are learned because of some problems that we need to solve.

Docker is developed based on the Go language. For details, you can check the official website of Docker to understand and learn.
Docker Official WebsiteDocker
DocumentationDocker
Mirror Warehouse

What can Docker do?

virtual machine technology

insert image description here

Disadvantages of virtual machine technology:

  • Very resource intensive
  • Many redundant steps
  • start very slow

container technology

Containerization is not a simulation of a full operating system

insert image description here

Compare the difference between Docker and virtual machine technology:

  • A traditional virtual machine virtualizes a piece of hardware, runs a complete operating system, and then installs and runs software on this system.
  • The application in the container runs directly in the kernel of the host machine. The container does not have its own kernel, nor does it virtualize our hardware, so it is portable.
  • Each container is isolated from each other, and each container has its own file system, which does not affect each other.

Devops (development, operation and maintenance)

Faster delivery and deployment of applications

Traditional: a bunch of help documents, installers.
Docker: Package image release test, run with one click.

Easier upgrade and expansion

After using Docker, we deploy applications just like building blocks.
The project is packaged as a mirror image, which can be expanded horizontally.

Easier system operation and maintenance

After containerization, our development and test environments are highly consistent.

More efficient use of computing resources

Docker is kernel-level virtualization, which can run many container instances on a physical machine, and the performance of the server can be squeezed to the extreme.

Docker installation

The basic composition of Docker

insert image description here

Image:
Docker image is like a template through which container services can be created, tomcat image —> run —> tomcat01 container (providing server), multiple containers can be created through this image (final service operation or project run in the container).

Container (container):
Docker uses container technology to run one or a group of applications independently and create them through mirroring.
Containers can be started, stopped, and deleted.
At present, this container can be understood as a simple linux system.

Warehouse (repository):
The warehouse is the place where the image is stored. The warehouse is divided into public warehouses and private warehouses.
Docker Hub (foreign by default), Alibaba Cloud, NetEase Cloud, etc. all have container servers (configured with mirror acceleration).

Install Docker

Environment preparation:

  1. A little basic knowledge of Linux is required
  2. CentOS 7
  3. Use Xshell to connect to the remote server for operation (here I am using VMware)

Environment view:

uname -r

cat /etc/os-release

# 系统内核是3.10以上
[root@wyc /]# uname -r
3.10.0-1160.el7.x86_64

# 系统版本
[root@wyc /]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

Install:

Docker help documentation

1. Uninstall the old version

# 卸载旧版本
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

2. Required installation packages

# 需要的安装包
yum install -y yum-utils

3. Set up a mirrored warehouse

# 设置镜像的仓库
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo # 默认是从国外的
yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 推荐使用阿里云的

# 安装容器之前,更新 yum 软件包索引
yum makecache fast

4. Install container-related docker-ce (community edition) and docker-ee (enterprise edition)

# 安装容器相关的 docker-ce
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

5. Start docker

# 启动 docker
systemctl start docker

6. Use docker version to check whether the installation is successful

# 查看是否安装成功
docker version

[root@wyc /]# docker version
Client: Docker Engine - Community
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:04:24 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:02:38 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.9
  GitCommit:        1c90a442489720eec95342e1789ee8a5e1b9536f
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

7. Verify that docker is installed correctly

seeHello from Docker!It is correctly installed!

# 验证 docker 是否安装正确
docker run hello-world

[root@wyc /]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

8. View the downloaded hello-world image

# 查看下载的 hello-world 镜像
docker images

[root@wyc /]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   13 months ago   13.3kB

Uninstall Docker:

# 1. 卸载依赖
yum remove docker-ce docker-ce-CLI container d . io docker-compose-plugin

# 2. 删除资源
rm -rf /var/lib/docker # docker的默认工作路径
rm -rf /var/lib/containerd

Alibaba Cloud Mirror Acceleration

1. Log in to Alibaba Cloud and find the container image service

Position is a column in flex compute

insert image description here

2. Find the image acceleration address

insert image description here

3. Configuration acceleration

sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
    
    
  "registry-mirrors": ["https://72ixx83s.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload

sudo systemctl restart docker

Run process and Docker principle

Flowchart of Run

insert image description here

underlying principle

How does Docker work?

Docker is a system of Client-Server structure. The Docker daemon process runs on the host and is accessed from the client through Socket. DockerServer will execute the command after receiving the command from Docker-Client.

insert image description here

Why is Docker faster than VM?

1. Docker has fewer abstraction layers than virtual machines
2. Docker uses the kernel of the host machine, and vm needs to be a Guest OS (that is, the virtual machine operating system in the figure below)

insert image description here

Therefore, when creating a new container, Docker does not need to reload an operating system kernel like a virtual machine to avoid booting. The virtual machine loads the Guest OS at the minute level, while Docker uses the host's operating system, omitting this complicated process, at the second level.

Other Differences Between Docker and VMs:
insert image description here
Sense Read! Please correct me if you have any questions!

Reference source: [Mad God Talks about Java] Docker's latest ultra-detailed tutorial is easy to understand

Guess you like

Origin blog.csdn.net/wyc837279588/article/details/127872703