一、方法一:
1、查看Docker默认存放数据目录
[root@k8s-node1 tools]# docker info | grep "Docker Root Dir"
WARNING: API is accessible on http://127.0.0.1:4243 without encryption.
Access to the remote API is equivalent to root access on the host. Refer
to the 'Docker daemon attack surface' section in the documentation for
more information: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
Docker Root Dir: /var/lib/docker
2、停止Docker服务
3、移动Docker数据目录到指定的分区
[root@k8s-node1 app]# mv /var/lib/docker /app/data/docker #这里/app为挂载的网络存储NAS
[root@k8s-node1 app]# ln -s /app/data/docker /var/lib/docke #软链接到原来的目录
4、启动Docker服务查看存储目录
[root@k8s-node1 ~]# docker info|grep "Docker Root Dir"
WARNING: API is accessible on http://127.0.0.1:4243 without encryption.
Access to the remote API is equivalent to root access on the host. Refer
to the 'Docker daemon attack surface' section in the documentation for
more information: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
Docker Root Dir: /app/data/docker
方法二:
1、/usr/lib/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 --exec-opt native.cgroupdriver=systemd --data-root=/data/docker_data
--insecure-registry=hub.ityy.ultrapower.com.cn:5050
$DOCKER_NETWORK_OPTIONS
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
EnvironmentFile=-/run/flannel/docker
[Install]
WantedBy=multi-user.target
2、查看是否生效
docker info|grep Dir
Docker Root Dir: /data/docker_data