Docker入门(2)配置文件详解
介绍
通过修改docker配置文件,调整默认存储位置、更换国内镜像源、信任私有仓库、日志格式及滚动策略等。修改docker配置文件,应该是docker安装完成之后必要执行的操作
1 编辑docker配置文件,没有则新建
$ vim /etc/docker/daemon.json
2 一般配置
{
"registry-mirrors": ["https://inhj05a1.mirror.aliyuncs.com"],
"data-root": "/data/docker",
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
- 配置说明:
data-root: 存储路径
registry-mirrors: 阿里云镜像仓库加速器
log-drive: 日志存储格式,设置为json文件格式
log-opts: 日志存储策略,单个日志文件最大100M,最多3个日志文件
3 生效配置
$ systemctl daemon-reload
$ systemctl restart docker
4. 所有参数说明
{
"authorization-plugins": [],
"data-root": "",
#Docker运行时使用的根路径,根路径下的内容稍后介绍,默认/var/lib/docker
"dns": [],
#设定容器DNS的地址,在容器的 /etc/resolv.conf文件中可查看
"dns-opts": [],
#容器 /etc/resolv.conf 文件,其他设置
"dns-search": [],
#设定容器的搜索域,当设定搜索域为 .example.com 时,在搜索一个名为 host 的 主机时,DNS不仅搜索host,还会搜索host.example.com。注意:如果不设置,Docker 会默认用主机上的 /etc/resolv.conf来配置容器。
"exec-opts": [],
"exec-root": "",
"experimental": false,
"features": {},
"storage-driver": "",
"storage-opts": [],
"labels": [],
#docker主机的标签,很实用的功能,例如定义:–label nodeName=host-121
"live-restore": true,
"log-driver": "",
"log-opts": {},
"mtu": 0,
"pidfile": "",
#Docker守护进程的PID文件
"cluster-store": "",
"cluster-store-opts": {},
"cluster-advertise": "",
"max-concurrent-downloads": 3,
"max-concurrent-uploads": 5,
"default-shm-size": "64M",
"shutdown-timeout": 15,
"debug": true,
#启用debug的模式,启用后,可以看到很多的启动信息。默认false
"hosts": [],
#设置容器hosts
"log-level": "",
"tls": true,
#默认 false, 启动TLS认证开关
"tlscacert": "",
#默认 ~/.docker/ca.pem,通过CA认证过的的certificate文件路径
"tlscert": "",
#默认 ~/.docker/cert.pem ,TLS的certificate文件路径
"tlskey": "",
#默认~/.docker/key.pem,TLS的key文件路径
"tlsverify": true,
#默认false,使用TLS并做后台进程与客户端通讯的验证
"tls": true,
"tlsverify": true,
"tlscacert": "",
"tlscert": "",
"tlskey": "",
"swarm-default-advertise-addr": "",
"api-cors-header": "",
"selinux-enabled": false,
#默认 false,启用selinux支持
"userns-remap": "",
"group": "",
#Unix套接字的属组,仅指/var/run/docker.sock
"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,
#默认true, 启用 net.ipv4.ip_forward ,进入容器后使用sysctl -a|grepnet.ipv4.ip_forward查看
"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": [],
#镜像加速的地址,增加后在 docker info中可查看。
"seccomp-profile": "",
"insecure-registries": [],
#配置docker的私库地址
"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}]
}
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
运维小记!
喜欢就支持一下吧
打赏
微信
支付宝