修改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
相关推荐
珠海西格电力2 小时前
西格电力零碳园区管理系统:核心功能全解析,赋能园区低碳智能化落地
大数据·运维·网络·人工智能·信息可视化·能源
深盾科技_Virbox2 小时前
软件授权工具静默安装实践
java·运维·数据库·安全·软件需求
qq_452396232 小时前
第二篇:《Jenkins 从零搭建:安装、配置与第一个 Pipeline》
java·运维·jenkins
Hui Baby2 小时前
kubeconfig 文件生成和赋权
运维
A_humble_scholar2 小时前
Linux(十七)深入多线程编程:同步原语与实战指南
linux·运维·c++
xinyu3913 小时前
旧版Ubuntu Docker镜像 apt 失败
linux·ubuntu·docker
ljs6482739513 小时前
Linux 实用命令:环境变量、文件传输、压缩解压、跨服务器传文件
linux·运维·服务器
AliCloudROS3 小时前
一次真实录屏:我只说每月别超过 200 块,小程序后端就搭好了
运维·人工智能·云计算
蓝狐社4 小时前
一张被低估的芯片版图——中兴通讯
运维·服务器