situation: Running a CentOS terminal in a docker container on a windows host. cv2 installed, working perfectly.
script:
import sys
import cv2
def main(argv):
inputfile = ''
for arg in argv:
img = cv2.imread(arg)
cv2.imshow('Image', img)
cv2.waitkey(0)
if __name__ == "__main__":
main(sys.argv[1:])
Error: : cannot connect to X server
Tried solution:[root@b26030f33e65 PythonScripts]# xhost local:root
xhost: unable to open display ""
2
Answers
On unix-like systems, you can pass-through the host’s X server (if any) to the docker container by setting up a set of required mounts (see this article for an idea).
Since you are on Windows, there’s hardly any chance that you can pass-through X from your host to your container since Windows does not run an X server; it uses other systems for on-screen rendering.
I think the only possible solution for you is to mount a directory from your host to your container and write your image to a file in that directory. It’s then easily accessible from your host system.
Just run your container with arguments similar to:
For windows you could try one of the various Xserver implementations, the most simple one being VcXsrv, other implementations are available from the Cygwin world and there are also some comercial solutions.
The main idea would be to start the Xserver making it to listen on TCP on all interfaces and without any auth then connect to it from the container over TCP
Note: listening on all interfaces and without auth is not the safe, you should use it only in the initial fase until you get the things running, afterwards you should take the necessary step to reduce the “exposed surface”.
Now … I’m not really sure how exactly to make you IP visible to the container, but I hope that this could be enough to get you started.
Later Edit:
I’ve found this (over-complicated) step-by-step guide, which basically says pretty much the same thing:
DISPLAY
env var pointing to your “display”