diff --git a/Dockerfile b/Dockerfile index 62f2366..d563d70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM prom/node-exporter:latest +USER root COPY entrypoint.sh /etc/node-exporter/ -RUN chmod +x /etc/node-exporter/entrypoint.sh - -ENTRYPOINT [ "/etc/node-exporter/docker-entrypoint.sh" ] -CMD [ "/bin/node_exporter" ] +ENTRYPOINT ["sh", "/etc/node-exporter/entrypoint.sh"] +CMD ["/bin/node_exporter"] diff --git a/README.md b/README.md index 0bf16e0..360f407 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a copy of [prom/node-exporter](https://hub.docker.com/r/prom/node-export ## Example -For the hostname to be detected, you must load the host filesystem into the container's `/host` directory as seen here. +For the hostname to be detected, you must mount the host's `rootfs` into the container's `/host` directory as seen here: ``` version: '3.8' @@ -21,5 +21,3 @@ services: deploy: mode: global ``` - -Otherwise use the `$HOSTNAME` variable to specify the path to the *hostname file* & ensure it's mounted. diff --git a/entrypoint.sh b/entrypoint.sh index 7efdb5d..7f5e1e4 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,6 @@ #!/bin/sh -if [ -z "$HOSTNAME" ]; then $HOSTNAME="/host/hostname"; fi - -NODE_NAME=$(cat "$HOSTNAME") +NODE_NAME=$(cat "/host/etc/hostname") echo "node_meta{node_name=\"$NODE_NAME\"} 1" > /etc/node-exporter/node-meta.prom set -- /bin/node_exporter "$@" exec "$@"