0

I have a docker-compose.yml with two services, Grafana and Ubuntu. I'm trying to run Prometheus and node_exporter commands in Ubuntu container through entrypoint but only works for the first command.

Dockerfile:

FROM ubuntu:20.04
ENV PROMETHEUS_VERISION=2.38.0
ENV NODE_EXPORTER_VERISION=1.4.0
RUN apt update -y && apt upgrade -y
RUN apt install -y wget
WORKDIR /
# Install Prometheus
RUN wget https://github.com/prometheus/prometheus/releases/downloa/v$PROMETHEUS_VERISION/prometheus-$PROMETHEUS_VERISION.linux-amd64.tar.gz && \
tar xvfz prometheus-$PROMETHEUS_VERISION.linux-amd64.tar.gz
ADD cstm_prometheus.yml /prometheus-$PROMETHEUS_VERISION.linux-amd64/cstm_prometheus.yml
EXPOSE 9090
# Install Node Exporter
RUN wget https://github.com/prometheus/node_exporter/releases/download/v$NODE_EXPORTER_VERISION/node_exporter-$NODE_EXPORTER_VERISION.linux-amd64.tar.gz && \
tar xvfz node_exporter-$NODE_EXPORTER_VERISION.linux-amd64.tar.gz
EXPOSE 9100
COPY ./cstm_entrypoint.sh /
RUN ["chmod", "+x", "/cstm_entrypoint.sh"]
ENTRYPOINT ["/cstm_entrypoint.sh"]

cstm_entrypoint.sh:

#!/bin/bash
./prometheus-$PROMETHEUS_VERISION.linux-amd64/prometheus --config.file=/prometheus-$PROMETHEUS_VERISION.linux-amd64/cstm_prometheus.yml
./node_exporter-$NODE_EXPORTER_VERISION.linux-amd64/node_exporter

When check the services on web browser i have access to:

  • grafana: 0.0.0.0:3000
  • prometheus: 0.0.0.0:9090

but not for node_exporter on 0.0.0.0:9100

Anybody could help me please? Thanks in advance.

  • ENTRYPOINT only supports one command, write your own shell script and place it there – tsamridh86 Sep 28 '22 at 09:39
  • This isn't really a symptom of using Docker. This is just how Bash files work. You could do something like [this](https://stackoverflow.com/questions/19233529/run-bash-script-as-daemon), but perhaps it might be better to run them each in their own Docker container rather than trying to run them all in one? – ProgrammingLlama Sep 28 '22 at 09:39
  • 1
    @tsamridh86 What? Like cstm_entrypoint.sh? – ProgrammingLlama Sep 28 '22 at 09:39
  • 1
    Usually you'd only run one process in a container, which means you'd run the Prometheus core and the node exporter in separate containers. Your Dockerfile makes it look like the two pieces are independent; can you build two separate images, one for each piece independently? – David Maze Sep 28 '22 at 10:06

1 Answers1

0

Your script waits for Prometheus to finish before it starts node_exporter. Try adding a & at the end of the Prometheus command to have it detach from the shell. Then the script will continue and run the node_exporter command. Like this

#!/bin/bash
./prometheus-$PROMETHEUS_VERISION.linux-amd64/prometheus --config.file=/prometheus-$PROMETHEUS_VERISION.linux-amd64/cstm_prometheus.yml &
./node_exporter-$NODE_EXPORTER_VERISION.linux-amd64/node_exporter
Hans Kilian
  • 18,948
  • 1
  • 26
  • 35