Install Glances in Docker

Introduction to Glances

There are many configurable widgets in Dashy, among which the most practical one is resource monitoring. Displaying CPU usage on the panel is not useful for me —— I am more concerned about which program is causing high CPU usage. However, the Glances software on which this feature depends is very practical.

Glances is similar to the top command, which can display system resource usage. However, it is better in the following aspects:

  • More comprehensive and user-friendly data display;
  • It can display the resource usage of each container —— in this respect, it surpasses Portainer. Portainer can only display the resource usage of one container in chart form.
  • It can run in server mode. We can monitor resource usage through a browser, which is very convenient.

image-20240408112645115

Glances is relatively lightweight, only displaying the current resource situation without recording historical data. And what I need is precisely this kind of lightweight yet comprehensive resource monitoring software.

Docker Installation

Why use Docker for installation? The official preferred method is to install via pip:

1
pip install --user glances

This will disrupt the local Python environment, so let’s use Docker instead.

docker compose:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
services:
glances:
image: docker.io/nicolargo/glances:latest
container_name: glances
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
network_mode: bridge
ports:
- 61208-61209:61208-61209
restart: unless-stopped
environment:
- GLANCES_OPT=-w
- TZ=Asia/Shanghai
pid: host

Then visit port 61208 in your browser.

References