LoginSignup
34
26

More than 5 years have passed since last update.

Docker上のGUI出力をMacで表示

Last updated at Posted at 2018-08-28

機械学習では多種多様な環境をDockerで使い分けるユースケースがありますが
サンプルコードなんかでよく見かけるmatplotlibなんかのGUIへの出力機能は
Docker上だと動きまへん
そこでDockerからホスト上のGUIへ直接出力する設定方法を備忘録として残す

前提

ubuntuです
今回のコンテナはこんな感じです

uname -a
Linux 9809f8c3404d 4.9.93-linuxkit-aufs #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

設定

ホスト側(Mac上)

# xquartzをセットアップ
brew cask install xquartz
# xquartzを起動しておきます
open -a XQuartz

XQuartzが起動したらセキュリティ設定(環境設定>セキュリティ)を変更しておきます
1. 「接続の認証」をOFF
2. 「ネットワーク・クライアントからの接続」をON

ゲスト側(Dockerコンテナ内)

apt-get update
apt-get install -y libx11-dev
export DISPLAY=host.docker.internal:0.0

version18.03からhost.docker.internalが利用可能になってたので修正しました
教えてくださったYOKO-Chanceさんに感謝

実行

Dockerコンテナ内でmatplotlibへimshowとかするPythonを実行すると
ホスト上で新規Windowが立ち上がり、結果を表示します。

34
26
3

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
34
26