概述
最近安装docker,想着把存储镜像和数据的默认路径放在磁盘空间更大的分区,结果发现镜像存储路径死活改不过来。问了AI,AI非说我装的不对。一气之下,翻开官方文档读了一遍,然后把文档扔给AI,骂了一顿。
文档
containerd image store with Docker Engine
Configure 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.toml
bash
croot@xunku:~# 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 = 2
root = "/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"
- 修改元数据默认路径,生效
- 加载配置
bash
systemctl daemon-reload
- 重启docker服务
bash
systemctl restart docker
- 修改镜像与容器快照默认路径,生效
- 停止docker服务
bash
systemctl stop docker
- 迁移当前目录
bash
rsync -av /var/lib/containerd/ 新目录/containerd/
- 启动docker服务
bash
systemctl start docker