Centos7安装docker
一、在线安装docker
1、查看linux发行版,内核
[root@localhost /]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
[root@localhost /]# uname -r
3.10.0-862.el7.x86_64
2、替换yum镜像(这里选择的是阿里云的)
#下载阿里yum源2
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#生成仓库缓存
yum makecache
3安装docker
yum install docker –y
4、启动docker
#启动docker
systemctl start docker
#开机启动
systemctl enable docker
#查看docker状态
systemctl status docker
5、验证
#查看docker版本
docker version
二、离线安装docker
Docker官方地址:docker down
将已下载好的docker离线包拷贝到服务器,解压压缩包
tar -xvf docker-18.09.6.tgz
将解压出来的docker文件内容移动到 /usr/bin/ 目录下
cp docker/* /usr/bin/
注册编辑docker服务
vim /etc/systemd/system/docker.service
写入以下内容后保存
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
添加权限后启动
chmod +x /etc/systemd/system/docker.service
重新加载配置文件
systemctl daemon-reload
启动Docker
systemctl start docker
设置开机自启
systemctl enable docker.service
验证是否安装成功
systemctl status docker
docker -v