修改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
相关推荐
北京中科新远科技3 分钟前
高速接口兼容排查实战:OSFP、QSFP112与QSFP56如何逐层验证
linux·运维·网络
Ruiery8 分钟前
Linux 6.6内核 CPU 深度解析(零):x86 内核引导协议 — 从 bootloader 到 main()
linux·运维·服务器
Ruiery8 分钟前
Linux 6.6内核 CPU 深度解析(十六):x86 保护机制 — 从 ring 到页表的权限防线
linux·运维·服务器
骑着蜗牛撵大象32724 分钟前
飞牛fnOS部署Damselfly:Compose编排、照片目录与7100固定访问
java·docker·rpc·dubbo·fnos·照片管理·damselfly
不老刘1 小时前
异构双 Agent 协同:构建无人值守的长任务自动化研发流水线
运维·人工智能·自动化·ai编程·1024程序员节
一掬净土1 小时前
kubelet 报错如下:docker does not support reopening container log files
docker·云原生·kubelet·logfiles
织码weavecodes1 小时前
医疗、零售、物业培训怎么落地?织码在线教育系统的三类行业案例
运维·服务器·零售
智能运维指南1 小时前
企业运维监控平台哪家好?2026年五大全栈可观测方案对比与选型推荐
大数据·运维·人工智能
乔旭伟2 小时前
部署形态选型笔记:多租户 SaaS 与单机本地部署的运维模型对比
运维·服务器·1024程序员节
姜鱼问生2 小时前
大屏突然 502?一次 Nginx Buffer 溢出引发的血案:upstream sent too big header
运维