码头工人_tkinter.TclError:无法连接显示 [英] docker _tkinter.TclError: couldn't connect to display

查看:199
本文介绍了码头工人_tkinter.TclError:无法连接显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ubuntu 16.04,安装了
nvidia-docker,运行了
a tensorflow容器,
python 2.7

ubuntu 16.04 , nvidia-docker installed, a tensorflow container running, python 2.7

我想运行一个简单的容器内的python代码。如下所示

i want to run a simple python code inside the container. shown as below

from tkinter import *
master = Tk()

canvas_width = 80
canvas_height = 40
w = Canvas(master, 
           width=canvas_width,
           height=canvas_height)
w.pack()

y = int(canvas_height / 2)
w.create_line(0, y, canvas_width, y, fill="#476042")


mainloop()

但是当我运行此命令时,会出现此错误

but when i run this, this error comes


_tkinter.TclError:没有显示名称,也没有$ DISPLAY环境变量

_tkinter.TclError: no display name and no $DISPLAY environment variable

,并根据此站点 https://github.com/moby/moby/issues/8838
i将我的容器提交给图像,然后使用-e标志再次运行它:

and according to this site https://github.com/moby/moby/issues/8838 i committed my container to an image, and run it again with the -e flag:


-e DISPLAY =:0.0

-e DISPLAY=:0.0

但出现错误:


_tkinter.TclError:无法连接会显示:0.0

_tkinter.TclError: couldn't connect to display :0.0

我没有使用ssh登录容器。
谁能给我建议吗?

i'm not using ssh to login the container. could anyone can give me advice about it?

推荐答案

这是因为容器无法访问主机的x11套接字。因此在执行docker run时,需要包含这两个标志。

This is because the container couldn't access the x11 socket of the host. so when doing the docker run, need to include these two flag.


-v /tmp/.X11-unix:/tmp/.X11-unix

-v /tmp/.X11-unix:/tmp/.X11-unix

-e DISPLAY = unix $ DISPLAY

-e DISPLAY=unix$DISPLAY

之后,我们需要执行另一项操作。因为X11的默认设置仅允许本地用户打印。因此我们需要将其更改为所有用户。

and after this, we need to do another operation. because the default settings of X11 only allows local users to print. so we need to change this to all users.


$ sudo apt-get install x11-xserver-utils

$ sudo apt-get install x11-xserver-utils

$ xhost +

$ xhost +

然后问题解决了。 ^ ^

then the problem solved. ^ ^

这篇关于码头工人_tkinter.TclError:无法连接显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆