环境准备
- CentOS 7 (Linux操作系统)
- Xshell(连接服务器工具)
环境准备看我这篇博客:XShell安装配置教程及云服务器 ECS(CentOS 7操作系统)的免费试用
环境查看
#系统内核
[root@iZ2ze04bxb1zhkn84xuy4uZ ~]# uname -r
3.10.0-1160.83.1.el7.x86_64
#系统版本
[root@iZ2ze04bxb1zhkn84xuy4uZ ~]# 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"
安装Docker
- Docker文档:https://docs.docker.com/
# 1:卸载旧版本
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 需要的安装包 系统自带
yum install -y yum-utils
#设置镜像仓库
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 makecahe fast
#安装docker docker-ce 社区版 ee 企业版
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
#启动docker
systemctl start docker
#使用docker versiong查看是否启动成功
docker version
# hello-world 证明安装成功
docker run hello-world
#查询下载的hello-word镜像
[root@iZ2ze04bxb1zhkn84xuy4uZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 17 months ago 13.3kB
- 了解如何卸载docker
#卸载依赖
yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
#删除资源
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
阿里云镜像加速
-
找到镜像地址
-
配置使用
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://t3p0czc5.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
- 拓展
阿里云镜像服务(简称为 ACR)相比 Dockerhub 的优势如下: 1. 简单易用。Dockerhub 部署在海外,拉取镜像时经常会遇到速度慢,不稳定等问题。ACR 在大部分地区提供存储能力,支持多地域,提供稳定快速的镜像上传、下载服务。 2. 安全可控。阿里云的镜像仓部提供镜像安全扫描功能,镜像如果有漏洞可以及时地扫描出来 并给用户提示,用户可根据提示修复镜像中的漏洞来避免一些安全问题。 3. 云产品间无缝集成。用户可以通过一些设置,直接在 Kubernetes 中拉取镜像,而不需要设 置额外密钥等。或者可以通过触发器,自动地更新容器中的应用。它还集成了云 Code,Code Pipeline,实现源代码到编译测试后,自动生成应用镜像,发布应用。