1. docker下载地址
https://download.docker.com/linux/static/stable/x86_64/
本文下载的 最新版本 docker-20.10.7.tgz
2. 安装
(1)先进行解压
tar -zxvf docker-20.10.7.tgz
(2)将解压后的文件拷贝到 /usr/bin/
cp docker/* /usr/bin/
(3)在/etc/systemd/system/目录下新增docker.service文件,内容如下,这样可以将docker注册为service服务
sudo touch /etc/systemd/system/docker.service
sudo vi /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 --selinux-enabled=false --insecure-registry=127.0.0.1
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
(4)启动docker
给docker.service文件添加执行权限
chmod +x /etc/systemd/system/docker.service
重新加载配置文件(每次有修改docker.service文件时都要重新加载下)
systemctl daemon-reload
启动:
systemctl start docker
设置开机启动
systemctl enable docker.service
查看docker服务状态
systemctl status docker
3.修改默认存储路径
(1)获取当前使用的存储驱动程序
docker info
(2)docker 服务停掉
sudo systemctl stop docker
(3)创建一个Drop-In 文件
# sudo mkdir /etc/systemd/system/docker.service.d
# sudo touch /etc/systemd/system/docker.service.d/docker.conf
创建Drop-In 文件的原因,是我们希望Docker 服务,使用docker.conf文件中提到的特定参数,将默认服务所使用的位于/lib/systemd/system/docker.service文件中的参数进行覆盖
(4)定义新的存储位置
sudo vi /etc/systemd/system/docker.service.d/docker.conf
写入以下内容
[Service]
ExecStart=
ExecStart= /usr/bin/dockerd --graph=/home/docker --storage-driver=overlay2
/home/docker 新的存储位置,而overlay2是当前docker所使用的存储驱动。
(5) 重新加载服务守护程序,并启动Docker服务
# sudo systemctl daemon-reload
# sudo systemctl start docker