Real-time host and container metrics compose example.
Educational example only. Review every volume path, port, and credential before you run this. Do not copy production secrets into your wiki or git repo.
_shared/.env for non-secrets, _shared/.secret for credentialsmkdir -p /path/to/docker/stacks/netdata
cd /path/to/docker/stacks/netdata
# paste compose.yaml below, then:
docker compose pull
docker compose up -d
services:
netdata:
image: netdata/netdata:latest
container_name: netdata
hostname: YOUR_HOST # Optional
env_file:
- /path/to/docker/stacks/_shared/.env
- /path/to/docker/stacks/_shared/.secret
pid: host
cap_add:
- SYS_PTRACE
- SYS_ADMIN
security_opt:
- apparmor:unconfined # Required on systems with AppArmor; use 'SELinux' equivalent if needed
volumes:
- /path/to/docker/data/netdata/netdataconfig:/etc/netdata
- /path/to/docker/data/netdata/netdatalib:/var/lib/netdata
- /path/to/docker/data/netdata/netdatacache:/var/cache/netdata
# Host mounts for full system monitoring
- /:/host/root:ro,rslave
- /etc/passwd:/host/etc/passwd:ro
- /etc/group:/host/etc/group:ro
- /etc/localtime:/etc/localtime:ro
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /etc/os-release:/host/etc/os-release:ro
- /var/log:/host/var/log:ro
# Docker socket for container monitoring (optional but recommended)
- /var/run/docker.sock:/var/run/docker.sock:ro
logging:
driver: json-file
options:
max-file: ${DOCKERLOGGING_MAXFILE:-10} # Max number of log files
max-size: ${DOCKERLOGGING_MAXSIZE:-200k} # Max file size
# Optional: Health check
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:19999/api/v1/info || exit 1"]
interval: 2m
timeout: 20s
retries: 3
network_mode: host
restart: unless-stopped