$ DISPLAY是否设置正确? -在docker容器中运行wxPython Phoenix GUI

问题描述 投票:0回答:1

我想对用wxPython Phoenix编写的GUI进行码头化,以便在运行docker映像时使GUI出现在主机上。

下面是基本的wxPython Phoenix GUI和Dockerfile,它使用Ubuntu 18.04Python 3.7.5wxPython 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"]
python docker user-interface xserver wxpython-phoenix
1个回答
0
投票

如问题中所述,DISPLAY变量在docker映像中用于存储主机的X服务器地址。根据主机,它应采用不同的值。

© www.soinside.com 2019 - 2024. All rights reserved.