Docker一般默认安装在/var/lib/docker目录下,对于云主机或云服务器默认系统盘不大的情况很不友好,动不动就是overlay占用很大空间。
将Docker默认安装位置迁移分为一下几步:
一、找到Docker默认安装位置
1 [root@XXXXXXX ~]# docker info 2 Client: 3 Context: default 4 Debug Mode: false 5 Plugins: 6 app: Docker App (Docker Inc., v0.9.1-beta3) 7 buildx: Docker Buildx (Docker Inc., v0.8.2-docker) 8 scan: Docker Scan (Docker Inc., v0.17.0) 9 10 Server: 11 Containers: 14 12 Running: 8 13 Paused: 0 14 Stopped: 6 15 Images: 14 16 Server Version: 20.10.17 17 Storage Driver: overlay2 18 Backing Filesystem: extfs 19 Supports d_type: true 20 Native Overlay Diff: true 21 userxattr: false 22 Logging Driver: json-file 23 Cgroup Driver: cgroupfs 24 Cgroup Version: 1 25 Plugins: 26 Volume: local 27 Network: bridge host ipvlan macvlan null overlay 28 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog 29 Swarm: inactive 30 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc 31 Default Runtime: runc 32 Init Binary: docker-init 33 containerd version: XXXX2954828e7c7c9b6e0ea9b0c02b01407XXX 34 runc version: v1.1.2-0-ga916309 35 init version: de40ad0 36 Security Options: 37 seccomp 38 Profile: default 39 Kernel Version: 3.10.0-1062.18.1.el7.x86_64 40 Operating System: CentOS Linux 7 (Core) 41 OSType: linux 42 Architecture: x86_64 43 CPUs: 2 44 Total Memory: 15.51GiB 45 Name: XXXX2tbvXXXZ 46 ID: IPOO:XXXO:Q7NC:QI3B:3XXX:HXXO:GIIF:XCMS:ELT3:GXXX:B6XG:6XXX 47 Docker Root Dir: /var/lib/docker 48 Debug Mode: false 49 Registry: https://index.docker.io/v1/ 50 Labels: 51 Experimental: false 52 Insecure Registries: 53 127.0.0.0/8 54 Live Restore Enabled: false
其中Docker Root Dir: /var/lib/docker就是安装目录。
二、创建或修改daemon.json配置文件
daemon.json 是 Docker 的配置文件,初始安装是没有被创建的,官网介绍说需要我们自己创建,它的目录在/etc/docker下。
下面是关于daemon.json文件配置参数的一个简单说明(注意:不是所有都要,后面有示例)
1 { 2 "authorization-plugins": [], 3 "data-root": "", # 设置docker运行时的根目录 4 "dns": [], # 设置容器的DNS地址 5 "dns-opts": [], # 设置容器的/etc/resolv.conf文件 6 "dns-search": [], 7 "exec-opts": [], 8 "exec-root": "", 9 "experimental": false, 10 "features": {}, 11 "storage-driver": "", 12 "storage-opts": [], 13 "labels": [], 14 "live-restore": true, 15 "log-driver": "json-file", 16 "log-opts": { 17 "max-size": "10m", 18 "max-files":"5", 19 "labels": "somelabel", 20 "env": "os,customer" 21 }, 22 "mtu": 0, 23 "pidfile": "", # 设置docker守护进程的PID文件 24 "cluster-store": "", 25 "cluster-store-opts": {}, 26 "cluster-advertise": "", 27 "max-concurrent-downloads": 3, 28 "max-concurrent-uploads": 5, 29 "default-shm-size": "64M", 30 "shutdown-timeout": 15, 31 "debug": true, # 是否以debug模式启动docker 32 "hosts": [], # 设置容器的hosts 33 "log-level": "", 34 "tls": true, 35 "tlsverify": true, 36 "tlscacert": "", 37 "tlscert": "", 38 "tlskey": "", 39 "swarm-default-advertise-addr": "", 40 "api-cors-header": "", 41 "selinux-enabled": false, # 设置是否支持SELinux 42 "userns-remap": "", 43 "group": "", 44 "cgroup-parent": "", 45 "default-ulimits": { 46 "nofile": { 47 "Name": "nofile", 48 "Hard": 64000, 49 "Soft": 64000 50 } 51 }, 52 "init": false, 53 "init-path": "/usr/libexec/docker-init", 54 "ipv6": false, 55 "iptables": false, 56 "ip-forward": false, 57 "ip-masq": false, 58 "userland-proxy": false, 59 "userland-proxy-path": "/usr/libexec/docker-proxy", 60 "ip": "0.0.0.0", 61 "bridge": "", 62 "bip": "", 63 "fixed-cidr": "", 64 "fixed-cidr-v6": "", 65 "default-gateway": "", 66 "default-gateway-v6": "", 67 "icc": false, 68 "raw-logs": false, 69 "allow-nondistributable-artifacts": [], 70 "registry-mirrors": [], # 设置镜像加速地址 71 "seccomp-profile": "", 72 "insecure-registries": [], # 设置docker的私有仓库地址 73 "no-new-privileges": false, 74 "default-runtime": "runc", 75 "oom-score-adjust": -500, 76 "node-generic-resources": ["NVIDIA-GPU=UUID1", "NVIDIA-GPU=UUID2"], 77 "runtimes": { 78 "cc-runtime": { 79 "path": "/usr/bin/cc-runtime" 80 }, 81 "custom": { 82 "path": "/usr/local/bin/my-runc-replacement", 83 "runtimeArgs": [ 84 "--debug" 85 ] 86 } 87 }, 88 "default-address-pools":[{"base":"172.80.0.0/16","size":24}, 89 {"base":"172.90.0.0/16","size":24}] 90 }
接下来创建一个daemon.json配置文件,注意,如果/etc下没有docker目录一定要先创建。
1 mkdir /etc/docker
然后,vi编辑器创建文件
1 vi /etc/docker/daemon.json
文件内容如下(/data/docker是我要迁移过去的文件夹):
{ "data-root": "/data/docker", # 填写你想迁移过去的文件夹路径 "log-driver": "json-file", "log-opts": { "cache-disabled": "false", "cache-max-file": "5", "cache-max-size": "20m", "cache-compress": "true", "max-size": "200m", "max-file": "5" }, "storage-driver": "overlay2", "registry-mirrors": [ "https://hub-mirror.c.163.com", "https://mirror.baidubce.com" ], "insecure-registries": [] }
ESC,:wq保存。这里千万注意,json文件中参数名前面的空格一定要用制表符,不要用4个空格,否则后面docker服务启动会失败!
三、停止docker服务,将现有的默认Docker安装路径下的文件复制到将要迁移的文件夹下
这里,我要迁移的目标是/data/docker
1 systemctl stop docker 2 cp -r /var/lib/docker /data # 这里要用/data而不是/data/docker是因为复制过去会自动生成一个docker文件夹
四、停止docker服务,并重启服务
1 systemctl daemon-reload 2 systemctl restart docker
大功告成!
标签:false,default,max,默认,CentOS7,json,Docker,docker From: https://www.cnblogs.com/sheng9hhd/p/18113176