centos8安装docker

centos8安装docker

不得不说国内的墙真是太厉害了,好的不好的都给你屏蔽了,这难道不是另外一种形式的闭关锁国?
无形中增加技术人员的难度,这不是为难我胖虎么?

配置国内dnf

1、dnf清除配置

1
dnf clean all

2、备份原dnf配置

1
mv /etc/yum.repos.d /etc/yum.repos.d.bak

3、创建新的dnf配置

1
2
3
4
5
mkdir /etc/yum.repos.d
 
cd /etc/yum.repos.d
 
vim CentOS-Base.repo

输入如下内容并保存

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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 - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
 
[PowerTools]
name=CentOS-$releasever - PowerTools - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/PowerTools/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
 
[AppStream]
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
#failovermethod=priority

4、重新生成dnf缓存

1
dnf makecache

至此dnf配置已经完成

安装yum工具配置国内镜像仓库

1、安转yum工具

1
yum install -y yum-utils

2、配置国内镜像仓库

1
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装docker

1、安装docker

1
docker-ce --nobest

2、配置docker国内国内镜像仓库地址

2.1、进入docker配置文件目录,没有则创建。

1
cd /etc/docker

2.2、编辑配置文件,没有则创建

1
vim daemon.json

输入如下内容并保存,其中指定了国内镜像加速地址和容器存放数据目录,这里建议修改成数据盘挂载目录。

1
2
3
4
5
{
"registry-mirrors": ["https://nsybtd8u.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.1.54:8000"],
"data-root":"/home/docker"
}

启动docker

1
2
3
systemctl enable docker
 
systemctl start docker

安装docker-compose

1、下载

1
sudo curl -L "https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

2、授权

1
sudo chmod +x /usr/local/bin/docker-compose

3、验证

1
docker-compose --version