首页 > 系统相关 >CentOS7下Docker容器默认安装位置迁移

CentOS7下Docker容器默认安装位置迁移

时间:2024-04-03 17:36:58浏览次数:15  
标签:false default max 默认 CentOS7 json Docker docker

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

相关文章

  • Docker部署zabbix6.0
    Dokcer部署zabbix6.0zabbix官网下载地址:https://www.zabbix.com/cn/downloadzabbix官方文档:https://www.zabbix.com/documentation/6.0/zh/manual服务器参数CPU:2U内存:8GBDocker版本:Dockerversion26.0.0,build2ae903e操作系统版本:openEuler-22.03-LTS-SP3创建zabbix......
  • [转]Docker 两个不同网络间实现连通
    原文地址:Docker两个不同网络间实现连通-西瓜君~-博客园一、启动不同网络的容器1、启动两个bridge(自带默认)桥接的容器[root@yang~]#dockerrun-it--nametomcat1tomcat[root@yang~]#dockerrun-it--nametomcat2tomcat#查看容器[root@yang~]#dockerps......
  • Docker安装hertzbeat
    快速安装开源监控软件hertzbeat官方链接hertzbeat官网地址:https://hertzbeat.com/hertzbeat官方文档:https://hertzbeat.com/docs/docker安装#拉取镜像dockerpulltancloud/hertzbeat#启动容器dockerrun-d-p1157:1157-p1158:1158\-eLANG=zh_CN.UTF-8\......
  • centos7:从源代码编译安装 nfs-ganesha
    安装依赖,依照手册编译、打包、安装即可。  yumcleanallyuminstall-ycentos-release-ceph-nautilusepel-releaseredhat-lsb-coreyummakecacheyuminstall-ygccgcc-c++makecmakezipunzipyuminstall-ybisonflexdoxygenrpm-buildyuminstall-yuse......
  • docker里面安装mariadb,设置用户名密码,登录mariadb
    5.启动Docker服务并设置开机自启动:  ```  sudosystemctlstartdocker  sudosystemctlenabledocker  ```###步骤2:在Docker中安装Nginx1.拉取Nginx镜像:  ```  sudodockerpullnginx  ```2.运行Nginx容器:  ```  sudo......
  • ⭐Unity 程序运行时默认出现在屏幕的左上角
    usingSystem.Runtime.InteropServices;usingUnityEngine;publicclassWindowPosition:MonoBehaviour{[DllImport("user32.dll",EntryPoint="SetWindowPos")]privatestaticexternboolSetWindowPos(IntPtrhwnd,inthWndInsertA......
  • docker构建镜像——Dockerfile
    COPY格式COPY[--chown=<用户>:<组>]<源>...<目的>COPY[--chown=<用户>:<组>]["<源>"..."<目的>"]案例[root@hmm~]#mkdiryum3-centos[root@hmm~]#lsanaconda-ks.cfgdocker-hellohello.csize......
  • 为Python应用选择最好的Docker镜像 转载
    在使用Python的早些年,为了解决Python包的隔离与管理virtualenvwrapper就成为我的工具箱中重要的一员。后来,随着Python3的普及,virtualenvwrapper逐渐被venv所替换。毕竟venv是Python3的标配,优点是显而易见的。而这几年,应用场景的的复杂性越来与高,无论是开发还是部......
  • docker------docker入门
    ......
  • 【Docker】专题六:Docker Registry 详解
    以下内容均来自个人笔记并重新梳理,如有错误欢迎指正!如果对您有帮助,烦请点赞、关注、转发!欢迎扫码关注个人公众号!目录一、基本介绍二、Registry创建方法三、Registry常用API请求四、Registry镜像清理一、基本介绍笔者在【Docker】专题一:Docker基本架构 中介绍......