Elastic Logging plugin for Docker: "error creating logger", "hosts flag is required"

128 views Asked by At

Running Docker 20.10.22 on Ubuntu 22.04 Jammy.

I'm trying to configure my Docker containers to log to Elastic Cloud, either by default through the mechanism of /etc/docker/daemon.json or through the use of command line flags.

I have tried with a daemon file like this:

me@server:~$ cat /etc/docker/daemon.json
{
  "log-driver": "elastic/elastic-logging-plugin:8.5.3",
  "log-opts": {
    "cloud_id": "...",
    "api_key": "...",
    "output.elasticsearch.index": "dockerlogs-wiki-%{+yyyy.ww}",
    "max-file": "10",
    "max-size": "4M"
  }
}

The Elastic Logging plugin is available and enabled:

me@server:~$ docker plugin ls
ID             NAME                                   DESCRIPTION              ENABLED
54832cf3f8f6   elastic/elastic-logging-plugin:8.5.3   A beat for docker logs   true

After restarting Docker with sudo systemctl restart docker to load the daemon.json I get this:

me@server:~$ docker create --name=container-name -v /var/run/docker.sock:/var/run/docker.sock:ro --restart=unless-stopped -h container-name --network=mynetwork ghcr.io/org/container-name:latest
09e3001a8a5507be2aa0cca44d3e9735dd7a6f4c3c59bb9f5a35c941f74fe240
me@server:~$ docker start container-name
Error response from daemon: failed to initialize logging driver: error creating logger: LogDriver.StartLogging: error creating client config: A hosts flag is required
Error: failed to start containers: container-name

I also tried with no daemon file, just CLI flags:

me@server:~$ docker create --name=container-name \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  --restart=unless-stopped \
  -h container-name \
  --network=wikinet \
  --log-driver=elastic/elastic-logging-plugin:8.5.3 \
  --log-opt cloud_id="..." \
  --log-opt api_key="..." \
  --log-opt max-file=10 \
  --log-opt max-size=5M \
  ghcr.io/org/container-name:latest
09e3001a8a5507be2aa0cca44d3e9735dd7a6f4c3c59bb9f5a35c941f74fe240
me@server:~$ docker start container-name
Error response from daemon: failed to initialize logging driver: error creating logger: LogDriver.StartLogging: error creating client config: A hosts flag is required
Error: failed to start containers: container-name

Same result. Any ideas on how to debug this would be more than welcome.

1

There are 1 answers

0
kthy On BEST ANSWER

Specifying --log-opt hosts="" makes the error go away and logs appear in Elastic Cloud. Shouldn't be necessary, but here we are.