0

I am trying to setup docker daemon on Centos 7.

The goal is to pass parameters to the overriding script in systemd and keep everything in daemon.json that is much more readable and cleaner

Default script /etc/systemd/system/docker.service.d/10-machine.conf is:

[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 still has the --label provider=generic that is the last parameter to move in daemon.json:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --label provider=generic

In /etc/docker/daemon.json i have already setup these parameters:

{
"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"]
}

I am not an expert about JSON format, so I stuck in passing "labels":.

I have tried "labels": ["provider=generic"] it doesn't work, dockerd fail to start

Any suggestion in order to pass it in the right way?

SOLUTION:

I have no idea why, but after I passed the value with a space before provider=generic,

(like this: [" provider=generic"]), daemon starts correctly:

{
"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"] 
}
fromthestone
  • 347
  • 4
  • 17

1 Answers1

0

Should just be:

{
"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"]
}

Perhaps you missed the comma between the keys (see the line before)?


Note, there should be no need to include a space before this field. There appears to be a typo or conflict somewhere. Perhaps a RedHat specific fork change to the daemon since the following works fine on 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"
]
BMitch
  • 5,966
  • 1
  • 25
  • 32
  • It doesn't work. If i put `"labels": ["provider=generic"]` (in the end as you shown me) i get this from logs: `unable to configure the Docker daemon with file /etc/docker/daemon.json: configuration validation from file failed (bad attribute format: provider-generic)` – fromthestone Feb 06 '19 at 15:38
  • @fromthestone do you have a `=` or `-` there? – BMitch Feb 06 '19 at 15:56
  • I have "=" in command line parameters, not "-", but the logs show "-" – fromthestone Feb 06 '19 at 15:57
  • @fromthestone command line parameters or daemon.json file? – BMitch Feb 06 '19 at 15:59
  • both daemon.json and command line parameters have "=", btw I found a solution and i have edited my question with that :-) – fromthestone Feb 06 '19 at 16:04
  • @fromthestone you shouldn't have command line parameters when you move it to the daemon.json. They are probably conflicting. – BMitch Feb 06 '19 at 16:08
  • sorry, probably I couldn't explain in the easiest way, but my meaning is that, remove all command line parameters and use daemon.json instead. The last parameter I couldn't pass was `--label provider=generic`. Now i have all parameters moved into json file and no more parameters in command line. The problem was just a missing space before provider=generic. ["provider=generic"] -> it doesn't work [" provider=generic"] - it works – fromthestone Feb 06 '19 at 16:14