Tuesday, May 28, 2019

[Docker] Using GUI with Docker

Recently I need to run my GUI application with Docker and it can show up either directly on my desktop operating system or in my ssh terminal client via X11.

Basically, there are some people who already provide the solution for the cases. I just list the reference and quickly give my examples.

1. Setup environment variables
# expose xhost so that the container can render to the correct display 
  by reading and writing though the X11 unix socket.
xhost +local:docker
XSOCK=/tmp/.X11-unix
# refers to an X authentication file with proper permissions
XAUTH=/tmp/.docker.xauth
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -

2. Display on x11 terminal's client or on host's desktop

docker run -it --net=host --name danny -e DISPLAY=$DISPLAY --env QT_X11_NO_MITSHM=1 \
 -v $XSOCK:$XSOCK \
 -v $XAUTH:$XAUTH \
 -v /home/test/danny:/danny \
 -v /var/run/docker.sock:/var/run/docker.sock \
 -e XAUTHORITY=$XAUTH \
 danny/inference_tool:v0 bash

    Another way to to do:

docker run -it --net=host --name danny -e DISPLAY=$DISPLAY --env QT_X11_NO_MITSHM=1 \
 --user $(id -u) \
 --volume="/home/$USER:/home/$USER" \
 --volume="/etc/group:/etc/group:ro" \
 --volume="/etc/passwd:/etc/passwd:ro" \
 --volume="/etc/shadow:/etc/shadow:ro" \
 --volume="/etc/sudoers.d:/etc/sudoers.d:ro" \
 -v /tmp/.X11-unix:/tmp/.X11-unix \
 danny/inference_tool:v0 bash

3. Get into your docker container 

docker exec -e COLUMNS=$COLUMNS -e LINES=$LINES -e TERM=$TERM -it danny bash

Reference:
https://towardsdatascience.com/real-time-and-video-processing-object-detection-using-tensorflow-opencv-and-docker-2be1694726e5?fbclid=IwAR0ceItanrFL13Uv9z4eK6zG_xgZb2924n4H8dkEZ7RnIMnuav4pKZlyJjA

https://github.com/tzutalin/labelImg


No comments: