本文主要是介绍更改docker默认数据目录的方法步骤,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
《更改docker默认数据目录的方法步骤》本文主要介绍了更改docker默认数据目录的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一...
1.查看docker是否存在并停止该服务
[root@hxy ~]# docker version Client: Docker Engine - Community Version: 27.2.1 API version: 1.47 Go version: go1.22.7 Git commit: 9e34c9b Built: Fri Sep 6 12:09:42 2024 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 27.2.1 API version: 1.47 (minimum version 1.24) Go version: go1.22.7 Git commit: 8b539b8 Built: Fri Sep 6 12:07:57 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.7.21 GitCommit: 472731909fa34bd7bc9c087e4c27943f9835f111 runc: Version: 1.1.13 GitCommit: v1.1.13-0-g58aa920 docker-init: Version: 0.19.0 GitCommit: de40ad0 [root@hxy ~]# systemctl stop docker Warning: Stopping docker.service, but it can still be activated by: docker.socket
2.挂载镜像并安装rsync便于编程备份
[root@hxy ~]# mount /dev/sr0 /mnt mount: /mnt: WARNING: source write-protected, mounted read-only. [root@hxy ~]# yum -y install rsync 正在更新 Subscription Management 软件仓库。 无法读取客户身份 本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。 上次元数据过期检查:0:04:09 前,执行于 2024年11月18日 星期一 14时38分34秒。 软件包 rsync-3.2.3-19.el9.x86_64 已安装。 依赖关系解决。 无需任何处理。 完毕! [root@hxy ~]#
3.取消挂载备份和迁移现有数据
[root@hxy ~]# umount /mnt(取消挂载) [root@hxy ~]# mkdir -p /mnt/docker-data(创建新数据目录) [root@hxy ~]# rsync -aP /var/lib/docker/ /mnt/docker-data/(备份数据) sending incremental file list ./ buildkit/cache.db 32,768 100% 0.00kB/www.chinasem.cns 0:00:00 (xfr#1, ir-chk=1103/1116) containers/0847c6969330b0e88bc78c4120221954dd6f321c334be357be83c23b673ec29c/ containers/0847c6969330b0e88bc78c4120221954dd6f321c334be357be83c23b673ec29c/config.v2.json 2,401 100% 2.29MB/s 0:00:00 (xfr#2, ir-chk=1081/1116) containers/0847c6969330b0e88bc78c4120221954dd6f321c334be357be83c23b673ec29c/hostconfig.json 1,461 100% 713.38kB/s 0:00:00 (xfr#3, ir-chk=1080/1116) containers/0899aa482296158404fe7e475b8ca64f571ef05fccaedb5279ce34cb2a1aa598/ containers/0899aa482296158404fe7e475b8ca64f571ef05fccaedb5279ce34cb2a1aa598/config.v2.json 2,393 100% 1.14MB/s 0:00:00 (xfr#4, ir-chk=1072/1116) containers/0899aa482296158404fe7e475b8ca64f571ef05fccaedb5279ce34cb2a1aa598/hostconfig.json 1,461 100% 475.59kB/s 0:00:00 (xfr#5, ir-chk=1071/1116) containers/217d978e1a191d798efdad2058b28a1cd21f938e0335c04038472b285c42e3ab/ containers/217d978e1a191d798efdad2058b28a1cd21f938e0335c04038472b285c42e3ab/config.v2.json 2,396 100% 584.96kB/s 0:00:00 (xfr#6, ir-chk=1063/1116) containers/217d978e1a191d798efdad2058b28a1cd21f938e0335c04038472b285c42e3ab/hostconfig.json 1,461 100% 285.35kB/s 0:00:00 (xfr#7, ir-chk=1062/1116) overlay2/ runtimes/ tmp/ volumes/ volumes/metadata.db 32,768 100% 0.00kB/s 0:00:00 (xfr#29, to-chk=0/26382)
4.修改docker配置文件
[root@hxy ~]# vi /etc/docker/daemon.json(删除原加速器内容) [root@hxy ~]# cat /etc/docker/daemon.json(查看输入内容) { "data-root": "/mnt/docker-data" }
5.验证新数据目录使用情况
[root@hxy ~]# systemctl start docker(开启docker)
[root@hxy ~]# systemctl status docker(查看当前状态)
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; prese>
Active: active (running) since Mon 2024-11-18 14:49:31 CST; 20s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 61352 (dockerd)
Tasks: 17
Memory: 53.2M
CPU: 1.016s
CGroup: /system.slice/docker.service
└─61352 /usr/bin/dockerd -H fd:// --containerd=/run/containerd>
11月 18 14:49:30 hxy dockerd[61352]: time="2024-11-18T14:49:30.772302169+08>
11月 18 14:49:31 hxy dockerd[61352]: time="2024-11-18T14:49:31.391786710+08>
11月 18 14:49:31 hxy dockerd[61352]: time="2024-11-18T14:49:31.565001457+08>
11月 18 14:49:31 hxy dockerd[61352]: time="2024-11-18T14:49:31.565120362+08>
11月 18 14:javascript49:31 hxy dockerd[61352]: time="2024-11-18T14:49:31.565160031+08>
11月 18 14:49:31 hxy dockerd[61352]: time="2024-11-18T14:49:31.565929847+08>
11月 18 14:49:31 hxy dockerd[61352]: time="2024-11-18T14:49:31.604773790+08>
11月 18 14:49:31 hxy dockerd[61352]: time="2024-11-18T14:49:31.604909987+08>
11月 18 14:49:31 hxy dockerd[61352]: time="2024-11-18T14:49:31.693026651+08>
11月 18 14:49:31 hxy systemd[1]: Started Docker Application Container Engin>
lines 1-22/22 (END)
[root@hxy ~]#
6.查看效果即可
[root@hxy ~]# docker info Client: Docker Engine - Community Version: 27.2.1 Context: default Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc.) Version: v0.16.2 Path: /usr/libexec/docker/cli-plugins/docker-buildx compose: Docker Compose (Docker Inc.) Version: v2.29.2 Path: /usr/libexec/docker/cli-plugins/docker-compose Server: Containers: 13 Running: 0 Paused: 0 Stopped: 13 Images: 2 Server Version: 27.2.1 Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Using metacopy: false China编程 Native Overlay Diff: true userxattr: false LogguPOskUing Driver: json-file Cgroup Driver: systemd Cgroup Version: 2 Plugins: Volume: local Network: bridge host ipvlan MACvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 runc Default Runtime: runc Init Binary: docker-init containerd version: 472731909fa34bd7bc9c087e4c27943f9835f111 runc version: v1.1.13-0-g58aa920 init version: de40ad0 Security Options: seccomp Profile: builtin cgroupns Kernel Version: 5.14.0-362.8.1.el9_3.x86_64 Operating System: Red Hat Enterprise Linux 9.3 (Plow) OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 1.879GiB Name: hxy ID: 5bfc3e44-6003-449e-bb96-93c320d6f2f2 Docker Root Dir: /mnt/docker-data(默认目录更改成功) Debug Mode: false Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
到此这篇关于更改docker默认数据目录的方法步骤的文章就介绍到这了,更多相关更改docker默认数据目录内容请搜索编程China编程(www.chinasem.cn)以前的文章或继续浏览下面的相关文章希望大家以后多多支持China编程(www.chinasem.cn)!
这篇关于更改docker默认数据目录的方法步骤的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!