一、离线安装
(1) 去官网下载docker 安装二进制包,选择适合自己的版本。这里下载的是docker-19.03.15.tgz,下载地址:https://download.docker.com/linux/static/stable/x86_64/
(2) 将安装包上传至安装机器
(3) 解压
tar -xf docker-19.03.15.tgz
(4) 将解压后的文件移至 /usr/bin/ 目录
mv docker/* /usr/bin/
(5) 创建服务启动文件
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
(6) 给服务启动文件加执行权限,并加载服务
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload
(7) 启动服务
systemctl start docker
(8) 设置开机启动
systemctl enable docker
二、docker镜像存储路径修改
2.1、软链接方式
(1) 查看镜像目录存储的路径
docker info|grep "Docker Root Dir"
#预期结果:
Docker Root Dir: /var/lib/docker
(2) 如有正在运行的docker容器,需要先关闭
docker ps | awk '{print $1}' |xargs docker stop
(3) 停止docker服务
systemctl stop docker
(4) 创建新的目录,并将原来的数据移到新目录
mkdir /app/docker
mv /var/lib/docker/* /app/docker
(5) 创建软链接
rmdir /var/lib/docker
ln -s /app/docker /var/lib/docker2
(6) 启动docker服务
systemctl daemon-reload
systemctl start docker
2.2、在daemon.json文件中配置(推荐)
(1) 查看镜像目录存储的路径
docker info|grep "Docker Root Dir"
#预期结果:
Docker Root Dir: /var/lib/docker
(2) 如有正在运行的docker容器,需要先关闭
docker ps | awk '{print $1}' |xargs docker stop
(3) 停止docker服务
systemctl stop docker
(4) 创建新的目录,并将原来的数据移到新目录
mkdir /app/docker
mv /var/lib/docker/* /app/docker
(5) 修改daemon.json文件(daemon.json文件不存在的话,新建一个即可)
vim /etc/docker/daemon.json
{
"data-root": "/app/docker", #配置新目录
"registry-mirrors": ["https://hub-mirror.c.163.com"] #镜像加速地址,按需配置
}
(6) 启动docker服务
systemctl daemon-reload
systemctl star docker