現象
devcontainer.json
でDISPLAY": "${localEnv:DISPLAY}"
と設定したのにコンテナ内でDISPLAY=:1
になっている(ホスト側はDISPLAY=:0
)という不可解な挙動がありました.
対策
dockerコマンドやdocker-compose.yml
, devcontainer.json
などから,
-
/tmp/.X11-unix
ディレクトリのマウント, -
DISPLAY": "${localEnv:DISPLAY}"
などのDISPLAY環境変数の設定
をすべて削除します.
It seems you don't need to specify DISPLAY or WAYLAND_DISPLAY or XDG_RUNTIME_DIR in the containerEnv section of the devcontainer.json any more. They are set automatically.
Therefore removing "DISPLAY": "${localEnv:DISPLAY}" from containerEnv fixed this issue for me. It is now set correctly automatically.
In addition I had to remove:
"-v",
"/tmp/.X11-unix:/tmp/.X11-unix",
from runArgs as this is now also handled automatically, and explicitly setting it had started causing issues.
この辺の設定はdevcontainerが自動でやってくれるみたいです.むしろ変にマウントするから不具合になっている?
余談
ホストがWSL2,Windows11,Ubuntuのコンテナでそれぞれ確認しました.Ubuntuのときコンテナ内はDISPLAY=:0
になっている一方で,ホストでwho
してディスプレイ番号見たら:1
でした.異なるディスプレイ番号でもOKなのはなぜ...?