0

I have a fully working docker-image running/hosted on my Ubuntu 18.04 linux machine. However, connecting to the physical machine via SSH from my Win10 Laptop via PowerShell:

ssh username@machine

I do get the following error from matplotlib when I try to execute my code remotely via ssh:

Traceback (most recent call last):
  File "foo", line 284, in <module>
    cnnTrainTestApply.applyStructureDetectionNet(absPathToCsvFiles, absPathToCnnOutputFiles)
  File "/home/dev/foo.py", line 702, in bar
    plt.figure(figsize=(15, 15))
  File "/opt/conda/lib/python3.5/site-packages/matplotlib/pyplot.py", line 539, in figure
    **kwargs)
  File "/opt/conda/lib/python3.5/site-packages/matplotlib/backend_bases.py", line 171, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "/opt/conda/lib/python3.5/site-packages/matplotlib/backend_bases.py", line 177, in new_figure_manager_given_figure
    canvas = cls.FigureCanvas(figure)
  File "/opt/conda/lib/python3.5/site-packages/matplotlib/backends/backend_qt5agg.py", line 35, in __init__
    super(FigureCanvasQTAggBase, self).__init__(figure=figure)
  File "/opt/conda/lib/python3.5/site-packages/matplotlib/backends/backend_qt5.py", line 235, in __init__
    _create_qApp()
  File "/opt/conda/lib/python3.5/site-packages/matplotlib/backends/backend_qt5.py", line 122, in _create_qApp
    raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable

Neither this, nor ssh -X username@machine do yield in success. Working directly on my machine without ssh does not make any issues. I suppose it is a missing XServer running, or something similar.

What do I get wrong about the ssh connection? How can I resolve the issue?

As matplotlib demands functioning qt5 backend, I can not simply avoid the forwarding of the X-server of the host system to docker.

Andreas
  • 307
  • 3
  • 14
  • 1
    Possible duplicate of [Alternatives to ssh X11-forwarding for Docker containers](https://stackoverflow.com/questions/25281992/alternatives-to-ssh-x11-forwarding-for-docker-containers) – Matthieu Brucher Nov 07 '18 at 14:53
  • It is not a duplicate of that issue. Since my problem is not about forwarding X11 to docker, that works fine. It is about not having X-Server running on a host that runs docker. When there is nothing to forward you can not forward. Thank you for the link! It provided some insights. To be more specific, the qt5 backend used by docker demands a Xserver running. Circumvention of the X-Server forwarding is not an option currently. – Andreas Nov 07 '18 at 14:59

1 Answers1

1

This solution is a workaround, that needs a logged in user with active X-Server. Which is not optimal.

As supposed DISPLAY is missing during the SSH-Connection. To use it for with matplotlib we have to do the following:

After the ssh login, on the host system "machine" do type following command before connecting to the docker image.

export DISPLAY=:1

This may depend on your machine setup, as long as you have the X-Server running with your current user, you may have to put the output of echo $DISPLAY instead of 1 as export. As long as the same usernames are provided this should work.

Andreas
  • 307
  • 3
  • 14
  • I think there were at least two similar questions about this within the last month or so. If you care, you could search for them and link them to your solution (or propose to mark as duplicate). – ImportanceOfBeingErnest Nov 07 '18 at 14:29
  • Oh, I have been searching for my issue quite a bit and found nothing really similar. Nor am I completely satisfied with my answer. If you do not mind, can you send me corresponding links. In any case, sorry for maybe having a redundant question asked! – Andreas Nov 07 '18 at 14:37
  • I did not find them either, so I just mentionned it here. Your solution seems at least much better than any of the comments below those as far as I recall; so this would be more like a service to those users. – ImportanceOfBeingErnest Nov 07 '18 at 14:39