Docker Swarm配置Prometheus Node-Exporter时--collector.enabled报错解决
--collector.enabled Error in Node-Exporter Docker Compose for Docker Swarm 3.3 Let's break down what's going wrong and how to fix it:
Why You're Seeing the Error
The unknown long flag '--collector.enabled' error happens because the version of prom/node-exporter you're using (likely a v0.x release) doesn't support this flag. The --collector.enabled parameter was introduced in Node-Exporter v1.0.0 as a way to explicitly list which collectors to enable. Older versions (v0.x) only let you disable collectors using the --no-collector.<collector-name> flag—most of the collectors you tried to list are enabled by default anyway.
On top of that, your final command line had a syntax mistake: wrapping the collector list in quotes is unnecessary in a Docker Compose command array. Each argument should be a separate array element, and YAML handles string parsing automatically without extra quotes.
Fix Option 1: Stick with the Older Node-Exporter Version
Since most of the collectors you want are enabled by default, you can just remove the invalid --collector.enabled line, and optionally disable any collectors you don't want using --no-collector flags. Here's the adjusted config:
services: node-exporter: image: prom/node-exporter volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - /:/rootfs:ro command: - '--path.procfs=/host/proc' - '--path.sysfs=/host/sys' - --collector.filesystem.ignored-mount-points - "^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)" - '--collector.textfile.directory=/etc/node-exporter/' # Add --no-collector flags for any collectors you want to disable - '--no-collector.bonding' - '--no-collector.btrfs' - '--no-collector.edac' - '--no-collector.hwmon' ports: - 9100:9100
If you don't need to disable any extra collectors, you can simply delete the invalid line entirely and keep the rest of your config as-is.
Fix Option 2: Upgrade to a Newer Node-Exporter Version
If you're able to upgrade, use a recent Node-Exporter image (e.g., v1.8.2 or the latest stable tag) that supports --collector.enabled. Adjust the flag to use a comma-separated list without extra quotes, like this:
services: node-exporter: image: prom/node-exporter:v1.8.2 # Use a recent version volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - /:/rootfs:ro command: - '--path.procfs=/host/proc' - '--path.sysfs=/host/sys' - --collector.filesystem.ignored-mount-points - "^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)" - '--collector.textfile.directory=/etc/node-exporter/' # Corrected --collector.enabled with comma-separated list - '--collector.enabled=conntrack,diskstats,entropy,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,stat,textfile,time,vmstat,ipvs' ports: - 9100:9100
This explicitly enables only the collectors you listed, which matches your original intent.
内容的提问来源于stack exchange,提问作者James Taylor

