Run x11 apps in a Docker container (supports network access from the container)

Run x11 apps in a Docker container (supports network access from the container)

I was able to get xeyes to work in the article "Show windows of X11 applications running on Docker containers on the display" (https://qiita.com/hoto17296/items/7c1ba10c1575c6c38105).

The --net host is specified as shown below.

$ docker run --rm -it \
    --net host \
    -e DISPLAY=$DISPLAY \
    -v $HOME/.Xauthority:/root/.Xauthority \
    xeyes

--net host uses a network that can only communicate between docker host and docker container.

So you can't use it if you want to connect to the internet from docker container.

In this article, we will enable the container to access the network and use the X11 app.

Dockerfile

Difference from Original

Contents of conf / Dockerfile

FROM alpine

RUN apk --no-cache add bash xeyes

CMD ["/bin/bash"]

build docker image

docker build -t xeyes conf

Only local users allow X connections

xhost +local:

Start container

Difference from Original

docker run --rm -it \
    -e DISPLAY=unix${DISPLAY} \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v $HOME/.Xauthority:/root/.Xauthority \
    xeyes

Confirm network access from container

bash-5.0# ping www.example.com
PING www.example.com (93.184.216.34): 56 data bytes
64 bytes from 93.184.216.34: seq=0 ttl=51 time=149.040 ms
64 bytes from 93.184.216.34: seq=1 ttl=51 time=172.391 ms
64 bytes from 93.184.216.34: seq=2 ttl=51 time=195.793 ms
^C
--- www.example.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 149.040/172.408/195.793 ms

Launch x11 app from container

bash-5.0# xeyes

Error message

If xhost + local: is not executed, the following error will occur.

bash-5.0# xeyes 
No protocol specified
Error: Can't open display: unix:0

GitHub

I put the Dockerfile and scripts I wrote in this article on GitHub.

https://github.com/m-tmatma/xeyes-docker

Recommended Posts

Run x11 apps in a Docker container (supports network access from the container)
[Docker] How to access the host from inside the container. http://host.docker.internal:
Access the network interface in Java
Run React on a Docker container
Run PureScript on a Docker container
Access MySQL on a Docker container from a local (host OS) Java program
How to check the logs in the Docker container
How to get a heapdump from a Docker container
I made a Docker container to run Maven
Build a container for Docker x Laravel phpMyAdmin
How Docker works ~ Implement the container in 60 lines
How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
3. Create a database to access from the web module
"LaTeX formula" embedded animation drawing environment Manim was successfully run in a Docker container (Macbook environment)
Copy and paste the file contents in Ubuntu's Docker container
Install / run a standalone robot simulator in wsl2 / docker environment!
[Docker] Delete only the volume associated with a specific container
Build a container that automatically formats Docker x Laravel code
[Docker context] ~ How to access docker in remote environment from VScode ~
802.1X authentication to the network of Bonding setting in CentOS7
Check by connecting the Docker container application under development from a device other than a PC (smartphone)
Decomposing the Docker run command. .. ..
Check the contents by docker pull from ECR and start the container
Build a browser test environment using Capybara in the Docker development environment
How to run a job with docker login in AWS batch
How to run a Kotlin Coroutine sample from the command line
Install lsb_release from the command line when lsb_release fails in docker environment
The story that Tomcat suffered from a timeout error in Eclipse