0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【個人的備忘録】パスワード保護付きGlances(Webサーバーモード)をDocker上で起動する

Last updated at Posted at 2025-08-18

Glancesで取得したサーバー情報を外部のサーバーで拾って一元監視したいと思ったのでメモ。
GlancesにはデフォルトでBasic認証を掛けられるオプションがあるので、Docker上で起動したGlancesをWebサーバーモードでかつパスワード保護付きで起動します。

基本的には以下のドキュメントの手順に従います。

環境

  • Ubuntu 22.04
  • Docker 27.3.1

GlancesをWebサーバーモードで起動する

Dockerがインストールされているかチェック

$ docker -v
Docker version 27.3.1, build ce12230

ルートディレクトリ直下にglancesディレクトリを作成
任意のテキストエディタでcompose.yamlを作成

$ mkdir glances
$ cd glances
$ nano compose.yaml

compose.yamlに設定を書き込み

services:
    glances:
        image: docker.io/nicolargo/glances
        container_name: glances
        restart: always
        ports:
            - 61208-61209:61208-61209
        environment:
            - GLANCES_OPT=-w
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:ro
            - /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock.ro
        pid: host

Docker Composeでコンテナを起動
psで起動確認

$ docker compose up -d
$ docker ps

この時点でポート番号61208でHTTPアクセスするとGlancesをブラウザから閲覧できるようになります。

パスワードファイルを作成

Glancesを使用してパスワードファイルを作成します。

コンテナのシェルを開く

$ docker exec -it glances sh

パスワードファイルを生成
(--usernameでユーザーネームを指定しない場合、デフォルトのglancesが使用されます)

$ glances -w --password

コンテナから退出

$ exit

コンテナ内からパスワードファイルをコピーする

$ docker cp glances:/root/.config/glances/glances.pwd ./glances/glances_password

compose.yamlを再編集

$ nano compose.yaml

environmentに--password、secretsをそれぞれ追加

services:
    glances:
        image: docker.io/nicolargo/glances
        container_name: glances
        restart: always
        ports:
            - 61208-61209:61208-61209
        environment:
            - GLANCES_OPT=-w --password
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:ro
            - /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock.ro
        pid: host
        secrets:
            - source: glances_password
              target: /root/.config/glances/glances.pwd

secrets:
    glances_password:
        file: /home/{UserName}/glances/glances_password

変更したcompose.yamlを適用する

$ docker compose up -d

適宜ファイアウォールの設定をする

$ ufw allow 61208

{IPアドレス}:61208で外部から閲覧可能か確認

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?