###### tags: `tutorials` `docker` `ubuntu` `linux` `cuda` `GPU` `NVIDIA` `python` `deep learning` `AI` # Docker 中使用 GUI 1. *run* container 時加入 `DISPLAY`、 `XAUTHORITY` 環境變數,設定 `net` 參數,將 `x server` 相關檔案掛載進 container ~~~bash= ! docker run -it -h $(hostname) -e DISPLAY=$DISPLAY -e XAUTHORITY=/tmp/xauth -v ~/.Xauthority:/tmp/xauth -v /tmp/.X11-unix:/tmp/.X11-unix --net=host -d {imageID_or_repo:Tag} ~~~ - `-h`: 將 container 的 host 設為和 local 相同 (因為 `~/.Xauthority` 會和主機名稱綁在一起) - `-e`: 設定 container 環境變數指令 - `DISPLAY=$DISPLAY`: 將 container 內部的 `DISPLAY` 參數使用的顯示 `port` 設成和外部使用者同一個 - `XAUTHORITY=/tmp/xauth`: 將 container 內部 `X server` 授權文件的 `XAUTHORITY` 參數設成和外部使用者同一個顯示授權文件 - `-v`: 外部授權相關文件掛載進 container - 將 `~/.Xauthority` 掛載進 container 的 `/tmp/xauth` - 將 `/tmp/.X11-unix` 掛載進 container 的 `/tmp/.X11-unix` - `--net`: 設定 container 連線方式, - `host`: 和主機使用相同連線方式 2. 進入 container 後,使用 `su {user_name}` 切換為外部使用者 (會在 container 內開啟新 shell) :::warning 如果一開始 container 沒有外部使用者,則需要照 container 外面(local)的 \$USER 跟 \$UID, 在 docker 裡面也建立一個同名同代號的 user: useradd -m -s /bin/bash -u {\$UID} {\$USER} :::
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.