修改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
相关推荐
wno7047 小时前
CentOS下FTP服务搭建
linux·运维·centos
mylove_北极甜虾7 小时前
jenkins-01Jenkins 架构与任务调度
运维·jenkins
tianyuanwo20 小时前
PostgreSQL 部署运维实战总结:从安装踩坑到生产可用
运维·数据库·postgresql
Decay__21 小时前
SQLServer 优化案例集 —— 慢 SQL 优化、索引重构与参数调整收益对比
运维·数据库·sql·mysql·架构
优化Henry1 天前
LTE 站点 S1 链路反复闪断导致小区频闪退服故障排查
运维·网络·学习·信息与通信·tdd
manageengine1 天前
服务器 CPU 100% 怎么排查:8 条命令从现象定位到根因
运维·服务器·cpu
分布式存储与RustFS1 天前
RustFS 分片上传怎么配:大文件断点续传的最小可验证流程
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
爱吃香菜的初学者1 天前
二十五.Linux——epoll
linux·运维·服务器
xbzb1 天前
Kubernetes 节点删除后还有残留?drain、reset 与集群销毁重建全流程
容器·kubernetes·kubectl·集群·reset·drain
宽海智能仓储物流1 天前
宽海智能WCS系统常见问题全解析:从选型对接、运维定制到降本增效
运维·数据仓库·自动化