Kubernetes certification exam self-study series | Install and configure docker

Book source: "CKA/CKAD Test Guide: From Docker to Kubernetes Complete Raiders"

Organize the reading notes while studying, and share them with everyone. If the copyright is violated, it will be deleted. Thank you for your support!

Attach a summary post: Kubernetes certification exam self-study series | Summary_COCOgsta's Blog-CSDN Blog


To manage containers and images, the system must install runtime (runtime). The so-called runtime is what manages containers. Docker is the runtime, and containerd is also the runtime. Here we mainly talk about the use of docker, so you need to install docker-ce first.

1.2.1 Install docker-ce

Step 1: Configure the yum source.

[root@vms100 ~]# rm -rf /etc/yum.repos.d/* ; wget -P /etc/yum.repos.d ftp://ftp.rhce.cc/k8s/*
...
100%[============>]276      --.-K/s用时Os

"/etc/yum.repos.d/k8s.repo"已保存 [276]

[root@vms100 ~]#
复制代码

Step 2: Install docker.

[root@vms100 ~]# yum install docker-ce -y
已加载插件:fastestmirror
base    | 3.6 kB 00:00:00
epel    | 5.4 kB 00:00:00
extras
...
作为依赖被升级:
  audit-libs.x86_64 0:2.8.4-4.el7       audit.x86_64 0:2.8.4-4.el7
...
  selinux-policy.noarch 0:3.13.1-229.el7_6.15
selinux-policy-targeted.noarch 0:3.13.1-229.el7_6.15

完毕!
[root@vms100 ~]#
复制代码

Step 3: Start docker and set it to start on boot.

[root@vms100 ~]# systemctl enable docker --now
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@vms100 ~]#
复制代码

1.2.2 Solve the problem of slow image download

Because when using docker pull to pull the image, the default is to pull the image from the docker hub, but the speed of visiting this website in China may be very slow. There are two ways to solve this problem: configure the accelerator and use the domestic image.

  1. Configure Alibaba Cloud Accelerator

Alibaba Cloud provides an accelerator link for downloading images. Go to Alibaba Cloud Console → Image Container Service → Image Accelerator, and you can see the address of the image accelerator provided by Alibaba Cloud, as shown in Figure 1-5.

Step 1: Edit /etc/docker/daemon.json, the content is as follows.

[root@vms100 ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://frz7i079.mirror.aliyuncs.com"]
}
[root@vms100 ~]#
复制代码

Step 2: Restart docker.

[root@vms100 ~]# systemctl restart docker 
[root@vms100 ~]#
复制代码

Step 3: Test pulling the nginx image.

[root@vms100 ~]# docker pull nginx
Using default tag:latest 
Trying to pull repository docker.io/library/nginx ...
latest: Pulling from docker.io/library/nginx 
1ab2bdfe9778: Pull complete
a17e64cfe253: Pull complete 
e1288088c7a8: Pull complete
Digest: sha256:53ddb41e46de3d63376579acf46f9a41a8d7de33645db47a486de9769201fec9
Status: Downloaded newer image for docker.io/nginx:latest
[root@vms100 ~]#
复制代码

You can see that after configuring the accelerator, you can quickly download the image from the docker official warehouse.

  1. Use NetEase Cloud Warehouse

Many domestic institutions have synchronized the images in the docker hub to their own image warehouses, such as Netease, Alibaba Cloud, Tsinghua University, etc.

Step 1: Go to the website c.163.com to register an account and log in, and then click Products and Services → Cloud Computing Basic Services → Mirror Warehouse → Mirror Center, as shown in Figure 1-6.

Enter the desired image in the search bar, such as centos, as shown in Figure 1-7.

Step 2: Click one of the nodes, such as library/centos in the above figure, and the result is shown in Figure 1-8.

Step 3: Click "Copy" in the upper right corner, paste it in the ssh client and press the [Enter] key.

[root@vms100 ~]# docker pull hub.c.163.com/library/centos:latest 
Trying to pull repository hub.c.163.com/library/centos ...
latest: Pulling from hub.c.163.com/library/centos 
2409c3878ba1: Pull complete
Digest: sha256:ab7e9c357fa8e5c822dd22615d3f704090780df1e089ac4ff8c6098f26a71fef 
Status: Downloaded newer image for hub.c.163.com/library/centos:latest 
[root@vms100 ~]#
复制代码
  1. Alibaba Cloud Warehouse

Step 1: Register an Alibaba Cloud account and log in, click Products and Services→Container Mirroring Service→Mirror Center→Mirror Search in the console.

Enter the image to be queried in the search bar, such as nginx, as shown in Figure 1-9.

Step 2: Click any search result, as shown in Figure 1-10.

In Figure 1-11, the upper right corner is the download address, and the lower part is the corresponding version. When downloading, combine these two parts, such as pulling version 1.2.

[root@vms100 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end:1.2
Trying to pull repository registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end
 ...
1.2: Pulling from registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end 
f2aa67a397c4: Pull complete
...输出...
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end:1.2
[root@vms100 ~]#

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/130179968