本文共 2608 字,大约阅读时间需要 8 分钟。
通常我们修改Docker的守护进程的一些特性是通过在/lib/systemd/system/docker.service这个配置文件的ExecStart后面增加启动参数,但是如果要设置的特性比较多,显然这个参数会很长。所以还是通过修改配置文件更加直观和方便。
配置文件在哪里:
在我们使用的这个Docker版本中,默认的配置文件是/etc/docker/daemon.json,但是这个文件并不存在,不过这个目录是存在的。
既然没有那个文件,我们就建立一个。这个文件的格式是JSON格式,其实没有什么难得,只要了解这个格式就可以写。大体格式如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | { "ITME1": "VALUE", "ITEM2": { "ITME2-1": "VALUE", "ITEM2-2": "VALUE", "ITEM2-3": { "ITEM2-3-1": "VALUE", } }, "ITEM3": [ "ITEM3-1=XXXX", "ITEM3-2=YYYY" ] } |
你只要知道格式,具体的值需要的时候再查询就行。下面是一个全的LINUX平台下的配置文件,来源于官网:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | { "api-cors-header": "", "authorization-plugins": [], "bip": "", "bridge": "", "cgroup-parent": "", "cluster-store": "", "cluster-store-opts": {}, "cluster-advertise": "", "debug": true, "default-gateway": "", "default-gateway-v6": "", "default-runtime": "runc", "default-ulimits": {}, "disable-legacy-registry": false, "dns": [], "dns-opts": [], "dns-search": [], "exec-opts": [], "exec-root": "", "fixed-cidr": "", "fixed-cidr-v6": "", "graph": "", "group": "", "hosts": [], "icc": false, "insecure-registries": [], "ip": "0.0.0.0", "iptables": false, "ipv6": false, "ip-forward": false, "ip-masq": false, "labels": [], "live-restore": true, "log-driver": "", "log-level": "", "log-opts": {}, "max-concurrent-downloads": 3, "max-concurrent-uploads": 5, "mtu": 0, "oom-score-adjust": -500, "pidfile": "", "raw-logs": false, "registry-mirrors": [], "runtimes": { "runc": { "path": "runc" }, "custom": { "path": "/usr/local/bin/my-runc-replacement", "runtimeArgs": [ "--debug" ] } }, "selinux-enabled": false, "storage-driver": "", "storage-opts": [], "swarm-default-advertise-addr": "", "tls": true, "tlscacert": "", "tlscert": "", "tlskey": "", "tlsverify": true, "userland-proxy": false, "userns-remap": "" "registry-mirrors": ["https://y49g0r41.mirror.aliyuncs.com"] } |
配置的时候你只需要挑选你需要的,不用全写进去。然后在dockerd命令后面使用--confige-file 知名配置文件就好,重复的就被覆盖了,不重复的则保持默认。下面举一个修改存储驱动和使用镜像加速器的实际的例子:
下面是一个使用加速器和私有仓库的例子:
参数说明:
参数 | 说明 |
bip | 设置容器网关地址,bip的含义是bridge ip,所以使用CIDR格式来设置网关IP,默认的是docker0。比如默认的是172.17.0.1,有些人想更改默认网桥分配的IP地址,你写成10.0.1.0/24显然是不对的,你这是网段而不是网桥的IP,所以你想把网络改成这个网段,那么你的bip应该是10.0.1.0/24 |
bridge | 指定使用哪个网桥,该网桥你可以通过docker network create建立,然后在这里指定 |
default-gateway | 指定容器的默认网关地址是多少,默认容器网关就是docker0网桥的IP,如果你想指定其他的地址,则需要用这个参数 |
fixed-cidr | 指定容器IP地址范围,这里是网段,你配置了bip之后如果没有特殊要求,这个参数可以不写。 |
mtu | 设置最大传输单元 |
dns | 设置容器的DNS服务器地址,可以是多个 |
本文转自linuxjavachen 51CTO博客,原文链接:http://blog.51cto.com/littledevil/1910423,如需转载请自行联系原作者