컨테이너로 올릴 때 걸리는 곳은 두 가지다 — 설정 파일 마운트와 데이터 볼륨 권한.
공식 이미지는 UID/GID 65534(nobody) 로 돈다. 호스트 디렉터리 소유자를 맞추지 않으면 기동하자마자 권한 오류로 죽는다.
sudo mkdir -p /opt/prometheus/{config,data}
sudo chown -R 65534:65534 /opt/prometheus/data
/opt/prometheus/config/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
- job_name: node
static_configs:
- targets: ['10.0.0.11:9100', '10.0.0.12:9100']
docker run -d --name prometheus \
-p 9090:9090 \
-v /opt/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml:ro \
-v /opt/prometheus/data:/prometheus \
--restart unless-stopped \
prom/prometheus:v3.14.0 \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/prometheus \
--storage.tsdb.retention.time=30d \
--web.enable-lifecycle
--web.enable-lifecycle 을 주면 재기동 없이 설정을 다시 읽을 수 있다.
curl -X POST http://localhost:9090/-/reload
이미지 태그를
latest로 두지 않는다. 메이저 업그레이드에서 TSDB 형식이 바뀌면 되돌리기 어렵다.
services:
prometheus:
image: prom/prometheus:v3.14.0
container_name: prometheus
restart: unless-stopped
ports:
- "9090:9090"
volumes:
- ./config/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus-data:/prometheus
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus
- --storage.tsdb.retention.time=30d
- --web.enable-lifecycle
volumes:
prometheus-data:
이름 있는 볼륨을 쓰면 권한 문제를 피할 수 있다.
컨테이너 안에서는 호스트를 볼 수 없다. node_exporter 를 따로 올린다.
docker run -d --name node-exporter \
--net=host --pid=host \
-v /:/host:ro,rslave \
--restart unless-stopped \
prom/node-exporter:v1.12.1 \
--path.rootfs=/host
curl -s http://localhost:9090/-/healthy
curl -s http://localhost:9090/api/v1/targets | head -c 400