Setting up Glances with Docker Compose
When I first bought a VPS, I wanted to try installing all kinds of self-hostable software in it. After deploying tens of applications I then wanted a monitoring tool to see the resource consumption of all the containers. A simple Google search listed `Prometheus`, `Netdata`, and `Cockpit` but I wanted something more like the `htop` terminal app. Well, `Glances` was just perfect and it solved my problem as it was lightweight and I could see how my server performed in real-time. I wanted to self-host Prometheus, well I found it difficult to crack the setup as I was new to self-host as well as docker.
Glances can be deployed with Docker with a Docker command as follows:
docker run -d --restart="always" /
--container_name="glances" /
-p 61208-61209:61208-61209 /
-e GLANCES_OPT="-w" /
-v /var/run/docker.sock:/var/run/docker.sock:ro /
--pid host docker.io/nicolargo/glances
To deploy using Docker Compose:
version: "3"
services:
glances:
container_name: glances
ports:
- 61208-61209:61208-61209
environment:
- GLANCES_OPT=-w
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
pid: host
image: nicolargo/glances:latest
This will open the ports 61208
and 61209
.
If you are using proxy service like traefik
then we could:
version: "3"
services:
glances:
container_name: glances
environment:
- GLANCES_OPT=-w
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
pid: host
image: nicolargo/glances:latest
networks:
- traefik-network
labels:
- traefik.enable=true
- traefik.http.routers.glances.rule=Host(`glance.example.com`)
- traefik.http.routers.glances.entrypoints=https
- traefik.http.services.glances.loadbalancer.server.port=61208
- traefik.http.routers.glances.tls=true
networks:
traefik-network:
external: true