我想对用wxPython Phoenix编写的GUI进行码头化,以便在运行docker映像时使GUI出现在主机上。
下面是基本的wxPython Phoenix GUI和Dockerfile,它使用Ubuntu 18.04
,Python 3.7.5
和wxPython Phoenix
创建映像。
运行图像时,它返回以下消息:
docker build -t simple-gui:latest .
docker run -it simple-gui /bin/bash
root@97229a17f2cd:~/python# ./simple_gui.py
Unable to access the X Display, is $DISPLAY set properly?
[我知道我必须将主机的X服务器的地址发送到docker映像,然后wxPython Phoenix会使用该映像,但我不确定该怎么做。
simple-gui.py :(来自wxPython Phoenix wiki)
#!/usr/bin/env python3.7
import wx
app = wx.App(False)
frame = wx.Frame(None, wx.ID_ANY, "Hello World")
frame.Show(True)
app.MainLoop()
Dockerfile:
FROM ubuntu:18.04
# Install dependencies for Python and wxPython Phoenix
RUN apt update && apt install -y \
libwebkitgtk-3.0-dev \
libgtk-3-dev \
libsm-dev \
freeglut3 \
freeglut3-dev \
libnotify-dev \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
dpkg-dev \
build-essential \
python3.7-dev \
libjpeg-dev \
libtiff-dev \
libsdl1.2-dev \
software-properties-common \
# Install Python 3.7 and pip latest versions
&& add-apt-repository ppa:deadsnakes/ppa \
&& apt install -y python3.7 python3-pip \
&& python3.7 -m pip install -U --no-cache-dir pip \
# Install wx
&& python3.7 -m pip install -U --no-cache-dir -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython
# Copy files
COPY simple_gui.py /root/python/
WORKDIR /root/python
ENTRYPOINT ["./simple_gui.py"]
如问题中所述,DISPLAY
变量在docker映像中用于存储主机的X服务器地址。根据主机,它应采用不同的值。