如何在简单的dockerized Python应用程序中显示输出?
我刚开始使用docker,并且仍然在使用中苦苦挣扎。 我有一个Python简单的Python应用程序,使用Matplotlib来生成一些简单的graphics。 我目前有以下Dockerfile:
FROM python:2 COPY requirements.txt / RUN pip install --requirement requirements.txt COPY my_code.py / CMD [ "python", "./my_code.py" ]
但是,这会产生以下错误:
Traceback (most recent call last): File "./fraud_detection_sample_code.py", line 161, in <module> plt.figure(1) File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 535, in figure **kwargs) File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 81, in new_figure_manager return new_figure_manager_given_figure(num, figure) File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 89, in new_figure_manager_given_figure window = Tk.Tk() File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 1820, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: no display name and no $DISPLAY environment variable
什么是解决这个问题的最好方法? 我的方法甚至可能吗?
你可以testing这个吗?
docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix your_image_name
它在类似的项目中为我工作。 想法从这里
- Windows Powershell以pipe理员身份运行时无法理解连接时的admin
- 使用Docker上的Php / Nginx的工艺CMS不能在Document Root之外编写
- 在Docker中用PhpStorm和XdebugdebuggingSymfony2
- docker化的DigitalOcean液滴中的MySQL容器,在docker-entrypoint-initdb.d目录中不运行sql命令
- 窗户10泊坞窗kitematic设置错误
- 在EC2上设置Docker Swarm
- Java Web应用程序和PostgreSQL上的Websphere自由
- 在运行docker化的.NET核心应用程序时创build装载源path时出错
- 无法使用Docker-Compose连接到NGINX