Ubuntu – How to fix X Error: BadAccess, BadDrawable, BadShmSeg while running graphical application using Docker

18.0420.04dockerfreematxserver

I am running Ubuntu MATE 20.04 LTS. I have installed Docker to this system.
I need to run FreeMat 4.2 which is not available for Ubuntu 20.04 LTS anymore because of Qt4 deprecation.

I did the following:

sudo apt-get install docker.io
sudo usermod -a -G docker $USER
# reboot

mkdir ~/docker-freemat
cat > ~/docker-freemat/Dockerfile << EOF
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y freemat
CMD freemat
EOF

docker build -t ubuntu:freemat ~/docker-freemat

To run FreeMat from container I'm using the following command:

docker run -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --user="$(id --user):$(id --group)" ubuntu:freemat

But the FreeMat window is non-functional, instead it looks like:

FreeMat from Docker

and terminal output is the following

X Error: BadAccess (attempt to access private resource denied) 10
  Extension:    130 (MIT-SHM)
  Minor opcode: 1 (X_ShmAttach)
  Resource id:  0x14e
X Error: BadShmSeg (invalid shared segment parameter) 128
  Extension:    130 (MIT-SHM)
  Minor opcode: 5 (X_ShmCreatePixmap)
  Resource id:  0x3200014
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode: 62 (X_CopyArea)
  Resource id:  0x3200015
...

How to get rid of this error and get application window shown normally and fully-functional?


Some notes:

  1. Changing 18.04 to 16.04 or even 14.04 in Dockerfile does not change anything
  2. Installing Docker from docker.com does not change anything

Best Answer

You can set the option --ipc=host to enable the docker container to communicate with host processes and also accessing the shared memories .

The command to launch graphical application will look as follows:

docker run --ipc=host -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --user="$(id --user):$(id --group)" ubuntu:freemat

and will show the application window:

FreeMat


MIT_SHM is actually an extension for passing the XImages and some Pixmaps via shared memory. So if the container cannot access that , you cannot open almost any graphical application.

And if you're concerned with the security , you can use --cap-drop to drop some capabilities as stated here.

Related Question