Linux安装Docker

Linux安装Docker

𝓓𝓸𝓷 Lv6
一、移除旧版本的Docker
1
2
3
4
5
6
7
8
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
二、安装Docker的依赖包
1
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
三、设置Docker的稳定仓库
1
2
3
4
5
6
7
8
9
10
11
12
13
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo


上面使用的官方提供的软件源速度非常慢,可以使用阿里源:
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

yum makecache fast
四、安装Docker Engine(社区版)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sudo yum install docker-ce docker-ce-cli containerd.io


---> Package docker-compose-plugin.x86_64 0:2.27.1-1.el7 will be installed
--> Finished Dependency Resolution
Error: Package: containerd.io-1.6.33-3.1.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2:2.74
Error: Package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64 (docker-ce-stable)
Requires: slirp4netns >= 0.4
Error: Package: 3:docker-ce-26.1.4-1.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2:2.74
Error: Package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64 (docker-ce-stable)
Requires: fuse-overlayfs >= 0.7
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest


如果安装报错,配置阿里YUM源,重新安装:
cd /etc/yum.repos.d
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release -y
yum install container-selinux -y #安装最新的contain-selinux
yum clean all
yum makecache
yum install docker-ce docker-ce-cli containerd.io
五、启动Docker服务
1
2
3
4
5
sudo systemctl start docker
sudo systemctl status docker

---配置开机自动启动docker
sudo systemctl enable docker
六、验证Docker是否正确安装
1
2
sudo docker -v
sudo docker run hello-world
七、镜像加速

鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,我们可以需要配置加速器来解决,我使用的是网易的镜像地址:http://hub-mirror.c.163.com。新版的 Docker 使用 /etc/docker/daemon.json(Linux) 或者 %programdata%\docker\config\daemon.json(Windows) 来配置 Daemon。请在该配置文件中加入(没有该文件的话,请先建一个)

1
2
3
4
5
6
7
8
9
10
11
[root@vip ~]# vim /etc/docker/daemon.json

{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}

或者

{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
  • Title: Linux安装Docker
  • Author: 𝓓𝓸𝓷
  • Created at : 2024-07-06 21:17:45
  • Updated at : 2024-08-11 12:37:38
  • Link: https://www.zhangdong.me/docker-installation.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论