I just started using docker and am still struggling a bit in it's usage. I have a python simple python application that uses Matplotlib to generate some simple graphs. I currently have the following Dockerfile:
FROM python:2
COPY requirements.txt /
RUN pip install --requirement requirements.txt
COPY my_code.py /
CMD [ "python", "./my_code.py" ]
This however generates the following error:
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
What would be the best way to solve this? Is it even possible with my approach?
Could you test this?
docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix your_image_name
It worked for me in a similar project. Idea from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With