我正在尝试在 Centos 7 上设置 docker 守护进程。
目标是将参数传递给覆盖脚本,systemd
并保持所有内容daemon.json
更易读、更清晰
默认脚本/etc/systemd/system/docker.service.d/10-machine.conf
是:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver overlay2 --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=generic --insecure-registry mtm-registry:5000
Environment=
/etc/systemd/system/docker.service.d/override.conf
仍然有--label provider=generic
要移动的最后一个参数daemon.json
:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --label provider=generic
我/etc/docker/daemon.json
已经设置了这些参数:
{
"storage-driver": "overlay2",
"hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2376"],
"tls": true,
"tlsverify": true,
"tlscacert": "/etc/docker/ca.pem",
"tlscert": "/etc/docker/server.pem",
"tlskey": "/etc/docker/server-key.pem",
"insecure-registries": ["my-registry:5000"]
}
我不是 JSON 格式的专家,所以我只是顺便说一下"labels":
。
我试过了"labels": ["provider=generic"]
,不行,dockerd
无法启动
有什么建议可以以正确的方式传递它吗?
解决方案:
我不知道为什么,但是在我传递了在 provider=generic 前有一个空格的值之后,
(像这样[" provider=generic"]
:),守护进程正确启动:
{
"storage-driver": "overlay2",
"hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2376"],
"tls": true,
"tlsverify": true,
"tlscacert": "/etc/docker/ca.pem",
"tlscert": "/etc/docker/server.pem",
"tlskey": "/etc/docker/server-key.pem",
"insecure-registries": ["mtm-registry:5000"],
"labels": [" provider=generic"]
}
答案1
应该只是:
{
"storage-driver": "overlay2",
"hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2376"],
"tls": true,
"tlsverify": true,
"tlscacert": "/etc/docker/ca.pem",
"tlscert": "/etc/docker/server.pem",
"tlskey": "/etc/docker/server-key.pem",
"insecure-registries": ["my-registry:5000"],
"labels": ["provider=generic"]
}
也许您错过了键之间的逗号(参见前一行)?
注意,此字段前不需要包含空格。似乎某处有拼写错误或冲突。可能是 RedHat 特定分支对守护进程的更改,因为以下内容在 Debian 上可以正常工作:
# # my daemon.json file does not have a leading space
# jq .labels </etc/docker/daemon.json
[
"foo=bar",
"provider=generic"
]
# # note you only need a reload here, I'm trying to reproduce the error
# systemctl restart docker
# docker system info --format '{{json .Labels}}' | jq .
[
"foo=bar",
"provider=generic"
]