Skip to content

Instantly share code, notes, and snippets.

@epoz
Created November 7, 2021 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epoz/93e9154c2dd83ec60bf2a701dd9a12ee to your computer and use it in GitHub Desktop.
Save epoz/93e9154c2dd83ec60bf2a701dd9a12ee to your computer and use it in GitHub Desktop.
Running Prometheus on Ubuntu 20.04 via docker

Prometheus on Ubuntu 20.04 via Docker

Installing Prometheus on a new server, I was a a bit confused that there seemed to be no good documentation on the main site for using it via Docker. There were also no instructions for running it via a custom PPA or someting, and the default pacakges installed via the package manager was a bit ouf of date?

What to do?

At first I tried running it via Docker, but then gave up, thinking it would be too much hassle to get the node exporter to access the host system for the metrics to be reported. There are various Googlejuice pages on manually installing and configuring a node, so this is what I did to start. But this still didn't 'feel' right.

So I asked around on Twitter, and got some very useful tips. The crucial one on running a node exporter in a container from Raffaele was actually the missing puzzle piece, and from there I could complete my setup. Thanks all!

So sharing it here as a complete setup, maybe someone else finds it useful. Might be good to post it upstream on the Prometheus site.

version: "3.7"
services:
node_exporter:
image: prom/node-exporter
container_name: prometheus_node
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- "--path.procfs=/host/proc"
- "--path.rootfs=/rootfs"
- "--path.sysfs=/host/sys"
- "--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($$|/)"
restart: always
prometheus:
image: myprometheus
container_name: prometheus
restart: always
ports:
- 9090:9090
FROM prom/prometheus
ADD prometheus.yml /etc/prometheus/
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
scrape_configs:
- job_name: node
static_configs:
- targets: ['node_exporter:9100']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment