docker安装后默认没有daemon.json这个配置文件,需要进行手动创建。配置文件的默认路径:/etc/docker/daemon.json
一般情况,配置文件 daemon.json中配置的项目参数,在启动参数中同样适用,有些可能不一样(具体可以查看官方文档),但需要注意的一点,配置文件中如果已经有某个配置项,则无法在启动参数中增加,会出现冲突的错误。
我们可以通过此地址https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file查看daemon.json文件所有可配参数
{ "authorization-plugins": [], "data-root": "", "dns": [], "dns-opts": [], "dns-search": [], "exec-opts": [], "exec-root": "", "experimental": false, "features": {}, "storage-driver": "", "storage-opts": [], "labels": [], "live-restore": true, "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file":"5", "labels": "somelabel", "env": "os,customer" }, "mtu": 0, "pidfile": "", "cluster-store": "", "cluster-store-opts": {}, "cluster-advertise": "", "max-concurrent-downloads": 3, "max-concurrent-uploads": 5, "default-shm-size": "64M", "shutdown-timeout": 15, "debug": true, "hosts": [], "log-level": "", "tls": true, "tlsverify": true, "tlscacert": "", "tlscert": "", "tlskey": "", "swarm-default-advertise-addr": "", "api-cors-header": "", "selinux-enabled": false, "userns-remap": "", "group": "", "cgroup-parent": "", "default-ulimits": { "nofile": { "Name": "nofile", "Hard": 64000, "Soft": 64000 } }, "init": false, "init-path": "/usr/libexec/docker-init", "ipv6": false, "iptables": false, "ip-forward": false, "ip-masq": false, "userland-proxy": false, "userland-proxy-path": "/usr/libexec/docker-proxy", "ip": "0.0.0.0", "bridge": "", "bip": "", "fixed-cidr": "", "fixed-cidr-v6": "", "default-gateway": "", "default-gateway-v6": "", "icc": false, "raw-logs": false, "allow-nondistributable-artifacts": [], "registry-mirrors": [], "seccomp-profile": "", "insecure-registries": [], "no-new-privileges": false, "default-runtime": "runc", "oom-score-adjust": -500, "node-generic-resources": ["NVIDIA-GPU=UUID1", "NVIDIA-GPU=UUID2"], "runtimes": { "cc-runtime": { "path": "/usr/bin/cc-runtime" }, "custom": { "path": "/usr/local/bin/my-runc-replacement", "runtimeArgs": [ "--debug" ] } }, "default-address-pools":[{"base":"172.80.0.0/16","size":24}, {"base":"172.90.0.0/16","size":24}]}
1、如何配置 registry 私库相关的参数
涉及以下2个参数:
"insecure-registries": [], #这个私库的服务地址 "registry-mirrors": [], #私库加速器
2.配置示例:
# cat /etc/docker/daemon.json { "registry-mirrors": [ "https://d8b3zdiw.mirror.aliyuncs.com" ], "insecure-registries": [ "https://ower.site.com" ], }
配置与应用
1.默认没有文件,所以我们需要先创建,进入/etc/docker目录下,记得创建的文件所有者是root(vim或touch,记得chown修改所有者)
-rw-r--r-- 1 root root 71 Dec 19 17:25daemon.json
2.在文档中配置想要添加的参数:如,镜像加速器网站,私库网站
# cat /etc/docker/daemon.json { "registry-mirrors":[ "https://d8b3zdiw.mirror.aliyuncs.com" ], "insecure-registries": [ "https://ower.site.com" ], }
3.创建并修改完daemon.json文件后,需要让这个文件生效
a.修改完成后reload配置文件
sudo systemctl daemon-reload
b.重启docker服务
sudo systemctl restart docker.service
c.查看状态
sudo systemctl status docker -l
d.查看服务
sudo docker info