修改Docker Engine 存储路径

概述

最近安装docker,想着把存储镜像和数据的默认路径放在磁盘空间更大的分区,结果发现镜像存储路径死活改不过来。问了AI,AI非说我装的不对。一气之下,翻开官方文档读了一遍,然后把文档扔给AI,骂了一顿。

文档

containerd image store with Docker Engine

Configure the data directory location

结论

  1. docker engine 29+的版本修改了镜像存储配置。镜像与数据存储拆分开,单独配置
  2. 如果使用overlay2 (the default for upgraded installations),镜像仍然默认存储在/var/lib/docker

配置

  1. 元数据默认路径: 默认/var/lib/docker
  • 配置文件: /etc/docker/daemon.json
  • 自定义配置:例如 "data-root": "/public/docker/var/lib/docker")
  1. 镜像与容器快照默认路径: 默认/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"
  1. 修改元数据默认路径,生效
  • 加载配置
bash 复制代码
systemctl daemon-reload
  • 重启docker服务
bash 复制代码
systemctl restart docker
  1. 修改镜像与容器快照默认路径,生效
  • 停止docker服务
bash 复制代码
systemctl stop docker
  • 迁移当前目录
bash 复制代码
rsync -av /var/lib/containerd/ 新目录/containerd/
  • 启动docker服务
bash 复制代码
systemctl start docker
相关推荐
木卫二号Coding1 小时前
推荐Linux统计文件大小并操作删除工具-ncdu
linux·运维·服务器
志栋智能2 小时前
超自动化运维:实现IT服务消费化的基础
运维·自动化
198******126343 小时前
2026企业AI办公工具选型指南:从评估框架到场景适配
大数据·运维·人工智能
吴声子夜歌3 小时前
Nginx应用与运维——Nginx HTTP模块详解(数据处理功能模块)
运维·nginx·http
2601_967212723 小时前
专利型电源轨道系统技术路线对比与选型框架
大数据·运维·网络·经验分享
数字化顾问4 小时前
(138页PPT)流程体系的建设优化与运营(附下载方式)
大数据·运维·人工智能
2601_967287575 小时前
轮胎侧壁上的 91V 是什么意思,负荷指数与速度级别怎么看
运维·服务器·汽车
小此方5 小时前
Linux网络(十九):TCP流量控制与滑动窗口详解,超时重传和快重传到底有什么区别
linux·运维·服务器·网络·网络协议·tcp/ip
海宇服务5 小时前
零信任架构实战:基于海宇运营商近3个月欠费次数构建自动化履约能力评估管线
运维·人工智能·架构·自动化
码上有光5 小时前
Linux进程通信——共享内存、消息队列和信号量
android·linux·运维·共享内存·通信