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?

proxmox Alpine LXCをnoVNC経由でGUIをインストールする

0
Last updated at Posted at 2026-06-12

環境

proxmoxVE9
Alpine3.22LXC

目的

proxmox Alpine_LXCにGUIをインストールし、noVNC経由でクライアントから操作する。
SSHターミナルから仮想ディスプレイを操作する検証

コンテナリソース

CPU:4
Mem:2GiB
Disk:16GiB

前提

root権限で操作する
コミュニティリポジトリ有効済み
Firewallは無効

スタック

x11vnc:
デスクトップ環境をそのままリモート操作する
noVNC:接続用プロキシ
ブラウザからVNC5900ポートに直接繋ぐのは困難なため

SSH接続準備

apk add openssh && echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && rc-service sshd start && rc-update add sshd

インストール

apk update
apk add bash
# GUI環境XFCEとVNCサーバー、日本語フォントをインストール
apk add xfce4 xfce4-terminal lightdm-gtk-greeter dbus-x11 ttf-dejavu x11vnc
#仮想的なディスプレイ環境を提供する
apk add xorg-server xvfb

GUI起動とVNCアクセスのためのスクリプト作成

GUI環境XFCEの仮想ディスプレイ:99で起動する。
そこにx11vncでアタッチする構成

cat << 'EOF' > /usr/local/bin/start-gui.sh
#!/bin/sh
nohup Xvfb :99 -screen 0 1280x720x24 > /dev/null 2>&1 &
export DISPLAY=:99
sleep 2
nohup startxfce4 > /dev/null 2>&1 &
sleep 5
nohup x11vnc -display :99 -nopw -listen 0.0.0.0 -xkb -forever > /dev/null 2>&1 &
EOF
chmod +x /usr/local/bin/start-gui.sh

続用プロキシ(noVNC)の準備

apk add python3 py3-pip
#pipを直インストールするなら。--break-system-packagesをpip installにつける。
python3 -m venv myenv
source myenv/bin/activate
pip install websockify --break-system-packages

自動起動の設定OpenRC

#サービス定義ファイルの作成
cat << 'EOF' > /etc/init.d/gui-vnc
#!/sbin/openrc-run
command="/usr/local/bin/start-gui.sh"
command_background="yes"
pidfile="/run/gui-vnc.pid"
depend() {
    need net
}
EOF
chmod +x /etc/init.d/gui-vnc
rc-update add gui-vnc default
rc-service gui-vnc start

apk add git
git clone https://github.com/novnc/noVNC.git /opt/noVNC

noVNCの実行

#全てのVNC関連プロセスを停止#もし起動コマンドを間違えた場合
kill -9 $(fuser 6080/tcp 2>/dev/null)
killall websockify
killall x11vnc
#実行
#x11vncの起動
x11vnc -display :99 -nopw -listen 0.0.0.0 -xkb -forever &
#noVNCの起動
/opt/noVNC/utils/novnc_proxy --vnc localhost:5900 --listen 6080 &

http://${IP}:6080/vnc.html

仮想ディスプレイを確認する

XサーバープロセスからディスプレイIDをしる

school-repo:~# ps aux | grep Xvfb
root         682  0.0  3.1 292152 80156 ?        S    09:52   0:01 Xvfb :99 -screen 0 1280x720x24
root        1129  0.0  0.0   1632   796 pts/4    S+   10:08   0:00 grep Xvfb

#現在のターミナルにディスプレイIDを教える
export DISPLAY=:99

echo "export DISPLAY=:99" >> ~/.bashrc
source ~/.bashrc
#ダミーの .Xauthority を作成する
#ないと認証ファイルを読みに行こうとしてエラーになる
touch ~/.Xauthority
# 認証キーを生成して登録
xauth add $DISPLAY . $(mcookie)

pyautoguiで確認してみる

mkdir dev-auto && cd dev-auto
apk install python3.12-venv -y
apk add python3-tkinter
apk add gnome-screenshot
python3 -m venv venv
source venv/bin/activate
pip install uv
uv pip install pyautogui pillow

確認

((venv) ) school-repo:~/dev-auto# python3 -m pyautogui
Xlib.xauth: warning, no xauthority details available
Xlib.xauth: warning, no xauthority details available
Press Ctrl-C to quit.
^C 1146 Y:  240 RGB: (  0,  72,  95)

firefoxを入れるなら

apk add firefox dbus-glib
apk add font-ipa font-noto-cjk
fc-cache -fv
apk add musl-locales
LANG=ja_JP.UTF-8 firefox --no-sandbox "https://www.google.co.jp" &
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?