2018-10-18 10:56:57 +03:00
.. _docker:
Docker
======
2023-06-24 17:22:19 +03:00
Glances can be installed through Docker, allowing you to run it without installing all the python dependencies directly on your system. Once you have `docker installed <https://docs.docker.com/install/> `_ , you can
2018-10-18 10:56:57 +03:00
Get the Glances container:
.. code-block :: console
2023-06-24 17:24:24 +03:00
docker pull nicolargo/glances:<version or tag>
2023-03-29 22:45:11 +03:00
2023-05-15 10:41:04 +03:00
Available tags (all images are based on both Alpine and Ubuntu Operating System):
2023-06-24 17:24:24 +03:00
.. list-table ::
:widths: 25 15 25 35
:header-rows: 1
* - Image Tag
- OS
- Target
- Installed Dependencies
* - `latest-full`
- Alpine
- Latest Release
- Full
* - `latest`
- Alpine
- Latest Release
- Minimal + (Bottle & Docker)
* - `dev`
- Alpine
- develop
- Full
* - `ubuntu-latest-full`
- Ubuntu
- Latest Release
- Full
* - `ubuntu-latest`
- Ubuntu
- Latest Release
- Minimal + (Bottle & Docker)
* - `ubuntu-dev`
- Ubuntu
- develop
- Full
.. warning ::
Tags containing `dev` target the `develop` branch directly and could be unstable.
For example, if you want a full Alpine Glances image (latest release) with all dependencies, go for `latest-full` .
2023-03-29 22:45:11 +03:00
2023-05-13 11:47:29 +03:00
You can also specify a version (example: 3.4.0). All available versions can be found on `DockerHub`_ .
2023-03-29 22:45:11 +03:00
An Example to pull the `latest` tag:
.. code-block :: console
docker pull nicolargo/glances:latest
2018-10-18 10:56:57 +03:00
Run the container in *console mode* :
.. code-block :: console
2023-05-16 12:03:02 +03:00
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro --pid host --network host -it docker.io/nicolargo/glances
2018-10-18 10:56:57 +03:00
Additionally, if you want to use your own glances.conf file, you can create your own Dockerfile:
.. code-block :: console
FROM nicolargo/glances
COPY glances.conf /glances/conf/glances.conf
CMD python -m glances -C /glances/conf/glances.conf $GLANCES_OPT
Alternatively, you can specify something along the same lines with docker run options:
.. code-block :: console
2023-05-16 12:03:02 +03:00
docker run -v `pwd` /glances.conf:/glances/conf/glances.conf -v /var/run/docker.sock:/var/run/docker.sock:ro -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro --pid host -it docker.io/nicolargo/glances
2018-10-18 10:56:57 +03:00
2018-11-28 01:06:03 +03:00
Where \`pwd\`/glances.conf is a local directory containing your glances.conf file.
2018-10-18 10:56:57 +03:00
2023-06-24 17:23:35 +03:00
Glances by default, uses the container's OS information in the UI. If you want to display the host's OS info, you can do that by mounting `/etc/os-release` into the container.
Here is a simple docker run example for that:
.. code-block :: console
docker run -v /etc/os-release:/etc/os-release:ro docker.io/nicolargo/glances
2018-10-18 10:56:57 +03:00
Run the container in *Web server mode* (notice the `GLANCES_OPT` environment variable setting parameters for the glances startup command):
.. code-block :: console
2023-05-16 12:03:02 +03:00
docker run -d --restart="always" -p 61208-61209:61208-61209 -e GLANCES_OPT="-w" -v /var/run/docker.sock:/var/run/docker.sock:ro -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro --pid host docker.io/nicolargo/glances
2018-10-18 10:56:57 +03:00
2019-07-03 23:41:54 +03:00
Note: if you want to see the network interface stats within the container, add --net=host --privileged
2018-10-18 10:56:57 +03:00
You can also include Glances container in you own `docker-compose.yml` . Here's a realistic example including a "traefik" reverse proxy serving an "whoami" app container plus a Glances container, providing a simple and efficient monitoring webui.
2019-07-03 23:41:54 +03:00
2018-10-18 10:56:57 +03:00
.. code-block :: console
version: '3'
services:
reverse-proxy:
image: traefik:alpine
command: --api --docker
ports:
2019-07-03 23:41:54 +03:00
- "80:80"
2018-10-18 10:56:57 +03:00
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
whoami:
image: emilevauge/whoami
labels:
- "traefik.frontend.rule=Host:whoami.docker.localhost"
monitoring:
2023-10-07 11:46:23 +03:00
image: nicolargo/glances:latest
2018-10-18 10:56:57 +03:00
restart: always
pid: host
2019-07-03 23:41:54 +03:00
volumes:
2018-10-18 10:56:57 +03:00
- /var/run/docker.sock:/var/run/docker.sock
2023-06-24 17:23:35 +03:00
# Uncomment the below line if you want glances to display host OS detail instead of container's
# - /etc/os-release:/etc/os-release:ro
2018-10-18 10:56:57 +03:00
environment:
- "GLANCES_OPT=-w"
2019-07-03 23:41:54 +03:00
labels:
- "traefik.port=61208"
2018-10-18 10:56:57 +03:00
- "traefik.frontend.rule=Host:glances.docker.localhost"
2020-12-24 00:18:58 +03:00
How to protect your Dockerized server (or Web server) with a login/password ?
2023-05-13 11:47:29 +03:00
-----------------------------------------------------------------------------
2020-12-24 00:18:58 +03:00
Below are two methods for setting up a login/password to protect Glances running inside a Docker container.
Option 1
^^^^^^^^
You can enter the running container by entering this command (replacing `` glances_docker `` with the name of your container):
.. code-block :: console
docker exec -it glances_docker sh
and generate the password file (the default login is `` glances `` , add the `` --username `` flag if you would like to change it):
.. code-block :: console
glances -s --password
2022-09-03 11:55:03 +03:00
2020-12-24 00:18:58 +03:00
which will prompt you to answer the following questions:
.. code-block :: console
2022-09-03 11:55:03 +03:00
Define the Glances server password (glances username):
Password (confirm):
2020-12-24 00:18:58 +03:00
Do you want to save the password? [Yes/No]: Yes
after which you will need to kill the process by entering `` CTRL+C `` (potentially twice), before leaving the container:
.. code-block :: console
2022-09-03 11:55:03 +03:00
2020-12-24 00:18:58 +03:00
exit
You will then need to copy the password file to your host machine:
.. code-block :: console
2022-09-03 11:55:03 +03:00
2020-12-24 00:18:58 +03:00
docker cp glances_docker:/root/.config/glances/glances.pwd ./secrets/glances_password
and make it visible to your container by adding it to `` docker-compose.yml `` as a `` secret `` :
.. code-block :: yaml
2022-09-03 11:55:03 +03:00
2020-12-24 01:18:08 +03:00
version: '3'
2022-09-03 11:55:03 +03:00
2020-12-24 00:18:58 +03:00
services:
glances:
image: nicolargo/glances:latest
2020-12-24 01:18:08 +03:00
restart: always
environment:
- GLANCES_OPT="-w --password"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
2023-06-24 17:23:35 +03:00
# Uncomment the below line if you want glances to display host OS detail instead of container's
# - /etc/os-release:/etc/os-release:ro
2020-12-24 01:18:08 +03:00
pid: host
2020-12-24 00:18:58 +03:00
secrets:
- source: glances_password
target: /root/.config/glances/glances.pwd
2022-09-03 11:55:03 +03:00
2020-12-24 00:18:58 +03:00
secrets:
glances_password:
file: ./secrets/glances_password
Option 2
^^^^^^^^
You can add a `` [passwords] `` block to the Glances configuration file as mentioned elsewhere in the documentation:
.. code-block :: ini
[passwords]
# Define the passwords list
# Syntax: host=password
# Where: host is the hostname
# password is the clear password
# Additionally (and optionally) a default password could be defined
localhost=mylocalhostpassword
default=mydefaultpassword
2023-03-29 22:45:11 +03:00
2023-05-12 22:10:18 +03:00
Using GPU Plugin with Docker (Only Nvidia GPUs)
2023-05-13 11:47:29 +03:00
-----------------------------------------------
2023-05-12 22:10:18 +03:00
Complete the steps mentioned in the `docker docs <https://docs.docker.com/config/containers/resource_constraints/#gpu> `_
to make the GPU accessible by the docker engine.
With `docker run`
^^^^^^^^^^^^^^^^^
Include the `--gpus` flag with the `docker run` command.
**Note:** Make sure the `--gpus` is present before the image name in the command, otherwise it won't work.
.. code-block :: ini
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro --gpus --pid host --network host -it docker.io/nicolargo/glances:latest-full
..
With `docker-compose`
^^^^^^^^^^^^^^^^^^^^^
Include the `deploy` section in compose file as specified below in the example service definition.
.. code-block :: ini
version: '3'
services:
monitoring:
image: nicolargo/glances:latest-full
pid: host
network_mode: host
volumes:
- /var/run/docker.sock:/var/run/docker.sock
2023-06-24 17:23:35 +03:00
# Uncomment the below line if you want glances to display host OS detail instead of container's
# - /etc/os-release:/etc/os-release:ro
2023-05-12 22:10:18 +03:00
environment:
- "GLANCES_OPT=-w"
# For nvidia GPUs
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
..
Reference: https://docs.docker.com/compose/gpu-support/
2023-03-29 22:45:11 +03:00
.. _DockerHub: https://hub.docker.com/r/nicolargo/glances/tags