Docker 修改默认存储位置
方法一、修改 docker daemon的启动参数-g, --graph=""
# Path to use as the root of the Docker runtime. Default is /var/lib/docker.
# 如 docker -d --graph=/opt/docker
# 我们可以通过修改 docker daemon的配置文件的方式来保存我们修改,方法如下:
# 默认情况下,docker daemon 会有一个默认的configuration 文件,此外,我们可以新建一个名为“daemon.json”文件的文件,我们在这个文件中的定义,会覆盖默认配置文件的内容文件。
### 修改
cd /etc/docker
vim daemon.json
# 在daemon.json文件中加入新的存储位置,
{
"data-root": "/data/docker"
}
# 重载load配置
systemctl daemon-load
# 重启docker
systemctl restart docker.serivce
# 查看已修改的docker存储位置
docker info
[smore@smore ~]$ sudo docker info
[sudo] password for smore:
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
Server:
Containers: 10
Running: 10
Paused: 0
Stopped: 0
Images: 6
Server Version: 20.10.2
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runtime.v1.linux nvidia runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc version: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.11.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 40
Total Memory: 62.8GiB
Name: smore
ID: UPJX:7N5G:JEBH:D6PB:IOI5:QKYT:FKIS:3UXV:PQ4I:SXCZ:HOXB:B3QS
Docker Root Dir: /home/docker_storage # 这里就是修改的新存储位置
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://kgltp33y.mirror.aliyuncs.com/
Live Restore Enabled: false