foreword
Well, the blogger here will first post some columns full of dry goods!
The first is a summary of bloggers’ high-quality blogs. The blogs in this column are all the bloggers’ most thoughtful writing. They are full of dry goods. I hope they will be helpful to everyone.
Then there is the blogger's most time-consuming column recently, "Docker From Understanding Practice to Underlying Principles", I hope everyone will pay more attention!
Chapter 3 - Introduction to docker
docker official website
docker installation
The blogger uses the centos7 system as a demonstration.
check your system
Check system and version.
cat /etc/*release*
(base) [yufc@ALiCentos7:~]$ cat /etc/*release*
CentOS Linux release 7.9.2009 (Core)
Derived from Red Hat Enterprise Linux 7.9 (Source)
cat: /etc/lsb-release.d: Is a directory
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"
CentOS Linux release 7.9.2009 (Core)
CentOS Linux release 7.9.2009 (Core)
cpe:/o:centos:centos:7
(base) [yufc@ALiCentos7:~]$
The blogger here is the Centos7 version of Linux.
Check the cpu architecture.
uname -a
(base) [yufc@ALiCentos7:~]$ uname -a
Linux ALiCentos7 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64 GNU/Linux
(base) [yufc@ALiCentos7:~]$
uninstall old version
The command is as follows.
sudo yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
Uninstall the previous version
sudo yum remove docker-ce docker-ce-cli containerd.io docker- buildx-plugin docker-compose-plugin docker-ce-rootless-extras # 删除机器上的包
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
sudo rm -rf /data/var/lib/docker
sudo rm -rf /etc/docker/daemon.json # 这是修改后的配置,根据实际情况进行设置
Configure the repository
This is the repository on our machine.
(base) [yufc@ALiCentos7:~]$ ll /etc/yum.repos.d/
total 32
-rw-r--r-- 1 root root 675 Apr 27 23:11 CentOS-Base.repo
-rw-r--r-- 1 root root 998 Dec 11 2018 CentOS-SCLo-scl.repo
-rw-r--r-- 1 root root 971 Oct 29 2018 CentOS-SCLo-scl-rh.repo
-rw-r--r-- 1 root root 230 Apr 27 23:11 epel.repo
-rw-r--r-- 1 root root 1358 Sep 5 2021 epel.repo.rpmnew
-rw-r--r-- 1 root root 1457 Sep 5 2021 epel-testing.repo
-rw-r--r-- 1 root root 1838 Apr 27 2017 mysql-community.repo
-rw-r--r-- 1 root root 1885 Apr 27 2017 mysql-community-source.repo
(base) [yufc@ALiCentos7:~]$
We need to install the warehouse given by docker into it
sudo yum install -y yum-utils # 安装最新的yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # 安装docker的仓库
At this time, there is one more docker-ce.repo
warehouse inside.
Configure to use domestic sources
sudo sed -i 's@//download.docker.com@//mirrors.ustc.edu.cn/docker-ce@g' /etc/yum.repos.d/docker-ce.repo
install latest version
sudo yum install -y docker-ce docker-ce-cli containerd.io docker- buildx-plugin docker-compose-plugin
start docker
#配置加载
sudo systemctl daemon-reload #启动服务
sudo systemctl start docker #开启启动
sudo systemctl enable docker #查看服务状态
sudo systemctl status docker # 查看状态
At this time, docker is in the started state!
View docker version
sudo docker version
sudo docker info
Docker installation practical experience
docker image source modification
cd /etc/docker/ # 进入docker配置的目录
touch daemon.json # 创建 daemon.json
vim daemon.json # 编辑这个文件
Type these in.
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
}
systemctl daemon-reload # 加载配置
systemctl restart docker # 重启docker服务
docker data directory adjustment
The default installation directory of Docker is /var/lib/docker
, which will store many, many images, so we need to consider the space of this directory when installing. There are three solutions.
- It will
/var/lib/docker
be mounted to a large disk. Generally, we can control the mount directory. Cloud vendors like Tencent Cloud provide mount options when installing K8s nodes. You can directly mount this directory in the past - Mount a large disk before installation, and then create a soft link to it
/var/lib/docker
, so that it will be automatically installed to our disk with a relatively large space - After installing docker, we found that we forgot to configure this directory. We need to modify the configuration file of docker.
#假定我们磁盘的大的目录为 /data mkdir -p /data/var/lib/docker # 编辑配置文件
vi /etc/docker/daemon.json
# 输入下面的json
{
"data-root": "/data/var/lib/docker"
}
# 加载配置
sudo systemctl daemon-reload
sudo systemctl restart docker # 重启docker
sudo systemctl status docker # 查看 docker 状态