1、将docker二进制包上传到服务器上,解压,并且将解压后的目录移动到/usr/local/下:
二进制tar包连接:https://pan.baidu.com/s/1HPxHuqu6Mn0BxHP_usVFUw
提取码:zhao
[root@node2 ~]# ls
docker-19.03.9.tgz
[root@node2 ~]# tar -xf docker-19.03.9.tgz
[root@node2 ~]# ls
docker docker-19.03.9.tgz
[root@node2 ~]# mv docker /usr/local/
[root@node2 ~]# ls /usr/local/docker/
containerd containerd-shim ctr docker dockerd docker-init docker-proxy runc
2、添加docker用户、修改环境变量
[root@node2 ~]# useradd -s /sbin/nologin docker -M
[root@node2 ~]# vim /etc/profile
#在最后一行添加一下内容
export PATH=$PATH:/usr/local/docker
#使用source重新加载环境变量配置文件
[root@node2 ~]# source /etc/profile
3、启动dockerd服务
[root@node2 ~]# nohup /usr/local/docker/dockerd &
##通过ps -ef|grep docker 查看docker服务是否启动
[root@node2 ~]# ps -ef|grep docker
root 3105 2911 0 21:11 pts/1 00:00:00 /usr/local/docker/dockerd
root 3112 3105 0 21:11 ? 00:00:03 containerd --config /var/run/docker/containerd/containerd.toml --log-level info
root 5668 2911 0 21:20 pts/1 00:00:00 grep --color=auto docker
4、查看docker版本信息
[root@node2 ~]# docker --version
Docker version 19.03.9, build 9d988398e7
出现以上信息说明docker安装好了。
第二种方法就是通过yum安装
1、安装系统必要的依赖工具
[root@node2 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
2、添加软件源信息
[root@node2 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
3、更新源并安装docker-ce
[root@node2 ~]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
[root@node2 ~]# yum makecache fast
[root@node2 ~]# yum -y install docker-ce
4、启动docker
[root@node2 ~]# systemctl start docker
[root@node2 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 一 2022-02-21 21:36:47 CST; 6s ago
Docs: https://docs.docker.com
Main PID: 5945 (dockerd)
Tasks: 8
Memory: 32.3M
CGroup: /system.slice/docker.service
└─5945 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock