母艦でubuntu26を使いはじめた。

xrdpコンテナも 自分のメモ 見ながらバージョン上げたる。

さて今回はどうやろ。gemini先生に手伝ってもらいながらやってみた。

ubuntu24のxrdpコンテナを停止

別マシンで作った実績あるから、ubuntu24のxrpdコンテナは保全せんでもええけどすぐには消さんとこか。

永続化領域は保全してあるから、名前ubuntu26用に名前変えてく。まずはubuntu24のコンテナ止めて永続化領域の名前変える。

1
2
3
4
5
6
7
8
nari@nafslinux-ubu26:/docker$ docker compose stop cl_ubu24gvis
[+] stop 1/1
 ✔ Container docker-cl_ubu24gvis-1 Stopped                                                      0.1s
nari@nafslinux-ubu26:/docker$ cd nariDockerDat/
nari@nafslinux-ubu26:/docker/nariDockerDat$ mv cl_ubun24/ cl_ubun26
nari@nafslinux-ubu26:/docker/nariDockerDat$ ll | grep ubun26
drwxrwxr-x  5 nari nari      4096 Jul 15  2024 cl_ubun26/
nari@nafslinux-ubu26:/docker/nariDockerDat$ 

compose.ymlを準備

⭐️の箇所を26に変える。 永続化領域もcl_ubun22からコピーして用意しとく。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  cl_ubu26gvis:                         ⭐️
    image: gvis-ubu26:26gvis            ⭐️
    privileged: true
    hostname: clubu26                   ⭐️
    ports:
      - "33389:3389"
    volumes:
      - ./nariDockerDat/cl_ubun26:/gvis ⭐️
    tty: true
    shm_size: 512m

Dockerfileを用意

dockerhubのubuntuの公開具合を見て26.04のタグがあることを確認しとく。

今回はrollingってタグのdigestが7b202b0e2e00って入ってた。

digestを検索すると、resoluteとlatestと26.04のタグにも同じのがついてる。

resolute raccoonやからresoluteやな。

gvis-docker-ubu26xrdp

26.04指定してdockerfile用意する。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# https://github.com/danchitnis/container-xrdp

FROM ubuntu:26.04 AS ububase

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get -y update 
RUN apt-get -y upgrade

RUN apt-get install -y \
    xfce4 \
    xfce4-clipman-plugin \
    xfce4-cpugraph-plugin \
    xfce4-netload-plugin \
    xfce4-screenshooter \
    xfce4-taskmanager \
    xfce4-terminal \
    xfce4-xkb-plugin \
    dbus  \
    dbus-x11

RUN apt-get install -y \
    sudo \
    wget \
    xorgxrdp \
    xrdp \
    tzdata \
    ibus \
    ibus-mozc \
    language-pack-ja-base \
    language-pack-ja \
    fonts-noto-cjk \
    fonts-noto-color-emoji && \
    apt remove -y light-locker xscreensaver && \
    apt autoremove -y && \
    rm -rf /var/cache/apt /var/lib/apt/lists

RUN locale-gen ja_JP.UTF-8 \
    && echo 'LC_ALL=ja_JP.UTF-8' > /etc/default/locale \
    && echo 'LANG=ja_JP.UTF-8' >> /etc/default/locale
ENV LANG=ja_JP.UTF-8 \
    LANGUAGE=ja_JP:ja \
    LC_ALL=ja_JP.UTF-8 \
    TZ=Asia/Tokyo
RUN cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
    && echo 'Asia/Tokyo' > /etc/timezone


COPY ./build/ubuntu-run.sh /usr/bin/
RUN mv /usr/bin/ubuntu-run.sh /usr/bin/run.sh
RUN chmod +x /usr/bin/run.sh

# https://github.com/danielguerra69/ubuntu-xrdp/blob/master/Dockerfile
RUN mkdir -p /var/run/dbus && \
    cp /etc/X11/xrdp/xorg.conf /etc/X11 && \
    sed -i "s/console/anybody/g" /etc/X11/Xwrapper.config && \
    sed -i "s/xrdp\/xorg/xorg/g" /etc/xrdp/sesman.ini && \
    echo "xfce4-session" >> /etc/skel/.Xsession

##############
## For gvis
##############

RUN apt-get -y update 
RUN apt-get -y upgrade

RUN apt-get install -y \
    fonts-ipafont \
    git \
    curl \
    featherpad \
    gvfs-backends \
    nmon \
    vim \
    dnsutils \
    iputils-ping \
    net-tools \
    iproute2 \
    mariadb-client \
    libreoffice \
    libreoffice-l10n-ja \
    libreoffice-dmaths \
    libreoffice-ogltrans \
    libreoffice-writer2xhtml \
    libreoffice-help-ja \
    mupdf \
    mupdf-tools \
    evince \
    file-roller \
    ristretto \
    software-properties-common \
    gnome-calculator && \
    apt autoremove -y && \
    rm -rf /var/cache/apt /var/lib/apt/lists

RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
RUN install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
RUN /usr/bin/sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
RUN apt install apt-transport-https
RUN apt update
RUN apt install code

RUN apt remove snap
## RUN apt-get install software-properties-common
RUN add-apt-repository ppa:mozillateam/ppa
RUN echo "Package: firefox*"                 >  /etc/apt/preferences.d/mozillateamppa
RUN echo "Pin: release o=LP-PPA-mozillateam" >> /etc/apt/preferences.d/mozillateamppa
RUN echo "Pin-Priority: 1001"                >> /etc/apt/preferences.d/mozillateamppa
RUN apt-get -y update 
RUN apt-get -y upgrade
RUN apt install firefox xul-ext-ubufox

## RUN curl https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
## RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list
## RUN apt-get -y update 
## RUN apt-get -y upgrade
## RUN apt install google-chrome-stable libu2f-udev

# 配下の.DS_Storeと._xxx を削除
RUN echo "function removegomi () {"                >> /root/.bashrc
RUN echo "  find . \( -name '.DS_Store' -or -name '._*' \) -delete -print;" >> /root/.bashrc
RUN echo "}"                                       >> /root/.bashrc
RUN echo "alias rmgomi=removegomi"                 >> /root/.bashrc

RUN echo "alias sc='cd /gvis/script'"              >> /root/.bashrc
RUN echo "alias tree=\"pwd;find . | sort | sed '1d;s/^\.//;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/|  /g'" \" >> /root/.bashrc
RUN echo "alias dff='df -h | grep -v DockerSys | grep -v "dev/loop"' "                                 >> /root/.bashrc
RUN echo "PATH=/gvis/script/proc:$PATH:$HOME/bin"  >> /root/.bashrc
RUN echo "export PATH"                             >> /root/.bashrc

RUN userdel -r `cat /etc/passwd | grep 1000 | awk -F':' '{print $1}'`
RUN useradd -m -s /usr/bin/bash -u 1000 nari

RUN sudo su - nari

# 配下の.DS_Storeと._xxx を削除
RUN echo "function removegomi () {"                >> /home/nari/.bashrc
RUN echo "  find . \( -name '.DS_Store' -or -name '._*' \) -delete -print;" >> /home/nari/.bashrc
RUN echo "}"                                       >> /home/nari/.bashrc
RUN echo "alias rmgomi=removegomi"                 >> /home/nari/.bashrc

RUN echo "alias sc='cd /gvis/script'"              >> /home/nari/.bashrc
RUN echo "alias tree=\"pwd;find . | sort | sed '1d;s/^\.//;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/|  /g'" \" >> /home/nari/.bashrc
RUN echo "alias dff='df -h | grep -v DockerSys | grep -v "dev/loop"' "                                 >> /home/nari/.bashrc
RUN echo "PATH=/gvis/script/proc:$PATH:$HOME/bin"  >> /home/nari/.bashrc
RUN echo "export PATH"                             >> /home/nari/.bashrc

FROM ububase

# Docker config
EXPOSE 3389
ENTRYPOINT ["/usr/bin/run.sh"]

ubuntu24のときと同じでほぼそのまま。

ビルド実行

ビルド時間かかるねんなぁ。

ビルドのやり方 - gemini先生に助けてもらう

前にgithubから公開元のdockerコンテナ材料を取ってきてビルドしてた。

1
2
3
4
5
cd /docker/nariDockerDat/cl_ubun26/download
git clone https://github.com/danchitnis/container-xrdp.git  ⭐️前に取ってきてもうあるからここはやらん
cd container-xrdp
vi ./ubuntu-xfce/Dockerfile-gvis.txt  ⭐️さっき用意したDockerfileを貼り付ける
docker build -f ./ubuntu-xfce/Dockerfile-gvis.txt -t ubu:26gvis .

git cloneはせず前のフォルダあるからそのまま使ったんやけど、そのまま使たら接続失敗したり真っ黒画面になったりした。

gemini先生に相談したら/usr/bin/run.shに問題あるらしいって教えてくれて、start_xrdp_servicesを書き換えてもらった。

gvis-docker-ubu26xrdp

何回かxrdpが接続失敗したので都度ログをgemini先生に渡して相談し、問題箇所を改善してもらいビルドやりなおしてった。

コメント添えて修正点を教えてくれるとは親切やな。

使えた最終版はこんな感じやけど、使いながら改善してくか。

/usr/bin/ubuntu-run.sh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash

start_xrdp_services() {
    # 1. 残存PIDファイルの削除
    rm -rf /var/run/xrdp-sesman.pid
    rm -rf /var/run/xrdp.pid
    rm -rf /var/run/xrdp/xrdp-sesman.pid
    rm -rf /var/run/xrdp/xrdp.pid

    # 2. D-Bus システムバスの起動
    mkdir -p /var/run/dbus
    dbus-daemon --system --fork > /dev/null 2>&1 || true

    # 3. PAM設定の修正(pam_systemdの無効化)
    if [ -f /etc/pam.d/xrdp-sesman ]; then
        sed -i 's/^session.*pam_systemd.so/#&/' /etc/pam.d/xrdp-sesman
    fi
    if [ -f /etc/pam.d/common-session ]; then
        sed -i 's/^session.*pam_systemd.so/#&/' /etc/pam.d/common-session
    fi

    # 4.xrdpのセッション起動スクリプト(startwm.sh)の作成(日本語入力環境変数のロードとfcitx5の自動起動)
    cat << 'EOF' > /etc/xrdp/startwm.sh
#!/bin/sh

# 日本語環境変数 (IBus用)
export LANG=ja_JP.UTF-8
export LC_ALL=ja_JP.UTF-8
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus
export XMODIFIERS=@im=ibus

# IBus デーモンの自動起動
ibus-daemon -rdx &

# デスクトップ環境の起動
exec startxfce4
EOF
    chmod +x /etc/xrdp/startwm.sh

    # 5. xrdp サービスの起動
    xrdp-sesman && exec xrdp -n
}

stop_xrdp_services() {
    xrdp --kill
    xrdp-sesman --kill
    exit 0
}

echo "Entryponit script is Running..."
echo

users=$(($#/3))
mod=$(($# % 3))

if [[ $# -eq 0 ]]; then 
    echo "No input parameters. exiting..."
    exit
fi

if [[ $mod -ne 0 ]]; then 
    echo "incorrect input. exiting..."
    exit
fi
echo "You entered $users users"

while [ $# -ne 0 ]; do

    addgroup $1 > /dev/null 2>&1 || true
    useradd -m -s /bin/bash -g $1 $1 > /dev/null 2>&1 || true
    wait
    
    echo "$1:$2" | chpasswd 
    wait
    
    if [[ $3 == "yes" ]]; then
        usermod -aG sudo $1
    fi
    wait

    # ユーザーホームの設定(パーミッションの正常化)
    USER_HOME="/home/$1"
    if [ -d "$USER_HOME" ]; then
        echo "startxfce4" > "$USER_HOME/.xsession"
        chmod +x "$USER_HOME/.xsession"
        chown -R $1:$1 "$USER_HOME"
    fi

    echo "user '$1' is added"

    shift 3
done

echo -e "This script is ended\n"
echo -e "starting xrdp services...\n"

trap "stop_xrdp_services" SIGKILL SIGTERM SIGHUP SIGINT EXIT
start_xrdp_services

ビルド結果

何度かやりなおして10分ぐらいかかった。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
nari@nafslinux-ubu26:/docker/nariDockerDat/cl_ubun26/download/container-xrdp$ docker build -f ./ubuntu-xfce/Dockerfile-gvis.txt -t ubu:26gvis .
[+] Building 2.0s (15/52)                                                            docker:default
[+] Building 2.1s (15/52)                                                            docker:default
 => [internal] load build definition from Dockerfile-gvis.txt                                  0.0s
[+] Building 2.3s (15/52)                                                            docker:default
 => [internal] load build definition from Dockerfile-gvis.txt                                  0.0s
 :(中略)
 => [ububase 48/48] RUN echo "export PATH"                             >> /home/nari/.bashrc   0.2s
 => exporting to image                                                                         3.2s
 => => exporting layers                                                                        3.2s
 => => writing image sha256:269c5b871e8929e82b0b184364ed9660a7f7c396181cf453d38ef9a75e4ed946   0.0s
 => => naming to docker.io/library/ubu:26gvis                                                  0.0s

 1 warning found (use docker --debug to expand):
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5)
nari@nafslinux-ubu26:/docker/nariDockerDat/cl_ubun26/download/container-xrdp$

イメージのサイズ確認してみる。

1
2
3
4
nari@nafslinux-ubu26:/docker$ docker images | egrep "24gvis|26gvis"
ubu:24gvis                   6dc67ff683a8       4.22GB             0B        
ubu:26gvis                   269c5b871e89       4.22GB             0B   U    
nari@nafslinux-ubu26:/docker$ 

まだdocker system pruneしてへんから24が残っとるな。サイズが24と同じやけどホンマに26でできとるんか?

ローカルlinuxのxrdpコンテナ

仮でコンテナ動かして、macからつないでみる。

docker run -it -v /docker/nariDockerDat/cl_ubun26:/gvis -p 33389:3389 ubu:26gvis nari password yes

xrdpコンテナへ接続してバージョン確認したら26にはなってるみたいやな。

gvis-docker-ubu26xrdp

xfceのネズミの壁紙見えて時計がJST、入力メソッドに日本語が使えたらうまいこといってる。

不足してるモジュールあってdbusでエラー出たり、mozcの起動がうまくできんかったり、5回ぐらい作り直した。

24のときにあった最初のxfce画面でネズミの背景画像が出えへんようになったな。

GUI設定は手動でやってく。キーボードのモデルは109がなかったから104キーってのを選んでおいて、レイアウトはOADG 109Aっての使ったら使えた。

  1. GUIの上パネルに見える時計を秒単位まで表示と、mozcへの切り替え、thunarのファイル表示を年月日時分秒に設定

  2. 母艦のubuntu24へsmb接続する認証情報の設定と、読み書きできること、パーミッション崩れがないことを確認

  3. xfceのシステムの設定でフォントをIPAゴシックに変更、キーボードを日本語配列にして(次にコンテナ起動したら有効になる)、壁紙設定と背景色を設定

  4. ターミナル内でdateって入れて日本語表示できてる確認と、alias設定でフォルダのツリー表示できる確認と、念のためaptの実行

  5. GUIの下パネルのほうにブラウザがあってfirefox起動できること、パネルに電卓/スクリーンショット/vscodeの追加

  6. firefoxをダークモードにしてフォントをIPAゴシックに変更し、母艦のapacheで公開しているURLをお気に入りに追加し、djangoページの認証情報を覚えさせる

  7. vscodeの起動オプションに--no-sandboxを足して.gitフォルダのあるフォルダを開いておき、プラグインにjapanese langpack/vscode-pdf/markdown pdf/gitgraph/git extensionを追加してからgitグラフ表示できるか確認

  8. テキストファイルをfeatherpadでダークモードで開く設定して、pdfがプレビューできる、xlsxファイルがlibreoofficeで開けることを確認

  9. google cloudのコンテナの場合はchrome起動してgmailとgoogle drive使えるように設定

GUIの設定は最初ハマった。

vscodeがなかなかうまく起動せんから、gemini先生に相談してbashrcにこう足した。

1
echo "alias code='code --no-sandbox --disable-gpu --disable-dev-shm-usage'" >> ~/.bashrc

これでええんかなぁ・・・。

gvis-docker-ubu26xrdp

手動設定いったん完了にしといてコミットしてイメージを置く。

dockerイメージはwindows/macのkubernetesに持ってって使うのよね。

そしたらGUIで手動設定した内容がkubernetesのpodで完全に同じ状態を維持して使えてまう。

docker commit `docker ps | grep 26gvis | awk '{print $NF}'` gvis-ubu26:26gvis

結果

いっつも一筋縄ではxrdpコンテナ稼働できん。

今回はxrdp起動のための/usr/bin/ubuntu-run.shの修正に時間かかった。

他にもvscode使えるようになるのに時間かかってcode --verboseって詳細ログをgemini先生に相談した。

少し様子見してからgoogle cloudとmicrok8sのホストも作ってくかな。

翌日にmacの中で動いてるrancher desktopのxrdpコンテナとdjango6をubuntu26ベースで使えるようにできたで。