docker - [02] 安装部署
一、环境准备
1、需要会一点点Linux基础
2、CentOS 7+
3、XShell连接服务器进行远程操作
序号 | 主机名 | IP | 操作系统 |
1 | ctos79-01 | 192.168.2.121 | Centos 7.9 |
2 | ctos79-02 | 192.168.2.122 | Centos 7.9 |
3 | ctos79-03 | 192.168.2.123 | Centos 7.9 |
二、环境检查
查看内核(
uname -r
)以及系统版本(cat /etc/os-release
)
三、安装部署
1、卸载旧的版本
查看命令
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2、需要的安装包:yum-utils
查看命令
yum install -y yum-utils
3、设置镜像的仓库,更新yum的软件包索引。
查看命令
# 配置镜像的阿里云仓库
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 更新yum软件包索引
yum clean all && yum makecache fast
4、安装docker相关的内容。(docker-ce 社区版 官方推荐使用、docker-ee 企业版)
查看命令
yum -y install docker-ce docker-ce-cli containerd.io
5、启动docker
6、查看docker版本:docker version
7、运行hello-world:docker run hello-world
8、查看下载的hello-world镜像
Tips:卸载docker
# 卸载掉docker引擎、客户端以及容器的包
yum remove docker-ce docker-ce-cli containerd.io
# 镜像、容器或者自定义的配置文件不会自动删除,需要手动删除
rm -rf /var/lib/docker
四、阿里云镜像加速
需要自行去阿里云注册,才能使用阿里云镜像加速功能。
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors":["https://qiyb9988.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
五、docker 运行原理
六、Q&A
安装docker失败,提示需要更新container-selinux、slirp4netns、fuse-overlayfs
检查发现,是我使用的yum源不行,于是更换了清华大学的yum源
然后继续执行docker -y install docker-ce docker-ce-cli containerd.io
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
— 要养成终生学习的习惯 —