I'm trying to use X forwarding via SSH to run GUI apps installed in a Ubuntu-based Docker container, but X forwarding isn't applied even I installed xauth with X11Forwarding yes in /etc/ssh/sshd_config. ($DISPLAY isn't defined.)
I tried to use X forwarding for real computers with the same configuration, and it worked well. ($DISPLAY is defined.)
Is X forwarding via SSH to Docker container really possible?


If the container is on your local machine it's easier to give the programs insider your container direct access to your X11 socket. For this you only need to mount /tmp/.X11-unix and ~/.Xauthority into your container and set $DISPLAY.

Assuming you use some_user with home dir /home/some_user/ to run your_program in container some_image use

docker run  -v /tmp/.X11-unix:/tmp/.X11-unix \
            -v ~/.Xauthority:/home/some_user/.Xauthority \
            --env DISPLAY=:0 --user some_user some_image your_program
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.