I want to manage my Swarm services using Docker Compose YAML format
docker command:
docker service create --name node-exporter \
--mode global \
--network proxy \
--mount "type=bind,source=/proc,target=/host/proc" \
--mount "type=bind,source=/sys,target=/host/sys" \
--mount "type=bind,source=/,target=/rootfs" \
--mount "type=bind,source=/etc/hostname,target=/etc/host_hostname" \
-e HOST_HOSTNAME=/etc/host_hostname \
basi/node-exporter:v0.1.1 \
-collector.procfs /host/proc \
-collector.sysfs /host/proc \
-collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)" \
-collector.textfile.directory /etc/node-exporter/ \
-collectors.enabled="conntrack,diskstats,entropy,filefd,filesystem,loadavg,m\
dadm,meminfo,netdev,netstat,stat,textfile,time,vmstat,ipvs"
compose.yml:
version: "3"
services:
node-exporter:
image: basi/node-exporter:v0.1.1
networks:
- mm
volumes:
- /proc:/host/proc
- /sys:/host/sys
- /:/rootfs
- /etc/hostname:/etc/host_hostname
environment:
- HOST_HOSTNAME=/etc/host_hostname
command: [ -collector.procfs,/host/proc,-collector.sysfs=/host/proc,-collector.filesystem.ignored-mount-points,"^/(sys|proc|dev|host|etc)($|/)",-collector.textfile.directory,/etc/node-exporter/,-collectors.enabled="conntrack,diskstats,entropy,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,stat,textfile,time,vmstat,ipvs"]
deploy:
mode: global
But got an error:Invalid interpolation format for "command" option in service "node-exporter": "^/(sys|proc|dev|host|etc)($|/)"
It seems that symbol $
caused. What format should I write it?
You can escape the $
symbol with another $
. See the variable substitution docs for more info.
thanks!
Spent over an hour to find this answer. Thank you.
You can use a $$ (double-dollar sign) when your configuration needs a literal dollar sign. This also prevents Compose from interpolating a value, so a $$ allows you to refer to environment variables that you don鈥檛 want processed by Compose.
web:
build: .
command: "$$VAR_NOT_INTERPOLATED_BY_COMPOSE"
Most helpful comment
You can escape the
$
symbol with another$
. See the variable substitution docs for more info.