修改Docker Engine 存储路径
概述最近安装docker想着把存储镜像和数据的默认路径放在磁盘空间更大的分区结果发现镜像存储路径死活改不过来。问了AIAI非说我装的不对。一气之下翻开官方文档读了一遍然后把文档扔给AI骂了一顿。文档containerd image store with Docker EngineConfigure the data directory location结论docker engine 29的版本修改了镜像存储配置。镜像与数据存储拆分开单独配置如果使用overlay2 (the default for upgraded installations)镜像仍然默认存储在/var/lib/docker配置元数据默认路径 默认/var/lib/docker配置文件 /etc/docker/daemon.json自定义配置例如 “data-root”: “/public/docker/var/lib/docker”镜像与容器快照默认路径 默认/var/lib/containerd配置文件 /etc/containerd/config.toml显示指定配置格式不建议启用 version 2 注意如果打开需要插件使用完整URL格式 io.containerd.grpc.v1.cri自定义配置例如root “/public/docker/var/lib/containerd”存储域配置项默认路径管理内容Docker 守护进程元数据data-root/var/lib/docker卷Volumes、网络配置、插件、服务定义等镜像与容器快照containerd.root/var/lib/containerd镜像层Layers、容器运行时快照注意修改自定配置后需要重启生效修改后的config.tomlcrootxunku:~# cat /etc/containerd/config.toml# Copyright 2018-2022 Docker Inc.# Licensed under the Apache License, Version 2.0 (the License);# you may not use this file except in compliance with the License.# You may obtain a copy of the License at# http://www.apache.org/licenses/LICENSE-2.0# Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an AS IS BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.disabled_plugins[cri]#disabled_plugins [io.containerd.grpc.v1.cri]#root /var/lib/containerd#version 2root/public/docker/var/lib/containerd#state /run/containerd#subreaper true#oom_score 0#[grpc]# address /run/containerd/containerd.sock# uid 0# gid 0#[debug]# address /run/containerd/debug.sock# uid 0# gid 0# level info修改元数据默认路径生效加载配置systemctl daemon-reload重启docker服务systemctl restartdocker修改镜像与容器快照默认路径生效停止docker服务systemctl stopdocker迁移当前目录rsync-av/var/lib/containerd/ 新目录/containerd/启动docker服务systemctl startdocker