menu Chancel's blog
rss_feed
Chancel's blog
时来天地皆同力

Docker默认存储路径更改

作者:Chancel Yang, 时间:2023 Jan 13, 阅读:9

Docker镜像对小容量的系统盘很不友好,其默认路径是/var/lib/docker,该路径通常没有特别大的硬盘空间

通过修改docker.service的配置来更改docker容器与镜像的存储位置

修改systemd的配置单,根据不同的操作系统其路径略有不同,可以通过查找/etc目录来获取

~ ➤ sudo find / -name 'docker.service*'                                                                                               
/etc/systemd/system/multi-user.target.wants/docker.service

暂停docker服务

sudo systemctl stop docker.service

在service节点的ExecStart中添加参数--graph,如下

~ ➤ sudo vim /etc/systemd/system/multi-user.target.wants/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
...

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph=/mnt/sdb/docker-lib
ExecReload=/bin/kill -s HUP $MAINPID
...

迁移Docker的文件到新目录下

sudo cp -r /var/lib/docker /mnt/sdb/docker-lib

应用设置

sudo systemctl daemon-reload
sudo systemctl start docker.service

检查docker运行是否异常,无异常后可删除/var/lib/docker目录

如果空间不足时打包镜像可能会引发 returned a non-zero code: 100的错误,更改存储位置确认空间足够后删除构建缓存即可

[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]