Cannot display pyvista plot in docker container

Hello everyone,

I am running FEniCSx in docker container inside VS Code environment. I am using Ubuntu 20.04 and running the poisson equation tutorial from the link:

https://jorgensd.github.io/dolfinx-tutorial/chapter1/fundamentals_code.html

I run docker with the following command:

docker run -ti -e DISPLAY=$DISPLAY -p 8888:8888 -v /media/Discone/Fenics/Docker:/media/Discone/Fenics/Docker -w /media/Discone/Fenics/Docker dolfinx/lab:latest

Everything works fine until pyvista tries the first plot. I get the following error:

[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://petsc.org/release/faq/#valgrind
[0]PETSC ERROR: or try http://valgrind.org on GNU/linux and Apple MacOS to find memory corruption errors
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run 
[0]PETSC ERROR: to get more information on the crash.
[0]PETSC ERROR: Run with -malloc_debug to check if memory corruption is causing the crash.
Abort(59) on node 0 (rank 0 in comm 0): application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0

I tried everything that i could find on the internet typing “pyvista in docke container”, “GUI application in docker container” etc. and, while other people seem to solve the issue, my best improvement is to get no error and anything else (neither the plot).

From pyvista website: https://docs.pyvista.org/extras/docker.html

I found that if i check Report Capabilities with:

print(pl.ren_win.ReportCapabilities())

And get

display id not set

means that my “environment is likely not set up correctly”.

What can I do? What in my environment is wrong?

Thank you.

You could have a look at: Dockerfile dolfinx/lab not able to run (em) tutorial? · Issue #74 · jorgensd/dolfinx-tutorial · GitHub
The key is that the tutorial uses some extra packages (pythreejs and ipygany), see: Implementation — FEniCSx tutorial which is not installed by default in the dolfinx/lab image

Hello dokken,
Unfortunately I tried what you say and I still get the same error. I also installed manually, one by one, all the requirements and nothing, still the same.
I feel like I am the only one on the internet that has something stupid that is wrong in the setup, because everything works for everone except me.

In the latest version of the tutorial I’ve created an image that includes all dependencies, (dokken92/dolfinx_custom:labv0.4.0), see: Tutorial compatible images for more details.

Still nothing, always getting the same error.
What do you get by printing

print(plotter.ren_win.ReportCapabilities())

?

I think that the reason of my problem is there. since I get

display id not set

And here: https://docs.pyvista.org/extras/docker.html
(as I already said) it says that something is wrong with my environment if I get this message.

I also get display id not set, but that is not a problem as I’m rendering the figures inside a jupyter notebook. Have you tried running the image in a browser?

You are right. I run it in the jupyter notebook and it works. Why it is not running in VS?

If it can help, a simple script that only uses matplotlib doesn’t work either.

I found the solution. Basically, if you run docker in VS there is no connection between the container and host’s X-server.
In the following link there are many ways to solve the issue:

http://wiki.ros.org/docker/Tutorials/GUI

I am following (for now) the 1st method that means to run:

xhost +local:root 

docker run -it \
     --net=host \
     --env="DISPLAY" \
     --env="QT_X11_NO_MITSHM=1" \
     --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
     --volume="$HOME/.Xauthority:/home/developer/.Xauthority:rw" \
     --volume="/media/Discone/Fenics/Docker:/media/Discone/Fenics/Docker" \
     --workdir="/media/Discone/Fenics/Docker"\
     dolfinx/dolfinx

of course the following are personal:
–volume="/media/Discone/Fenics/Docker:/media/Discone/Fenics/Docker"
–workdir="/media/Discone/Fenics/Docker"\

after working in docker container, run:

xhost -local:root

that returns access control to default.

2 Likes

Hello @bay_swiss , I have the same problem trying to run demo scripts using the Python IDE PyCharm with a remote interpreter which is configured by the corresponding docker image for that specific demo script. I get the same error messages like you pointed out here:

I do not quite understand how u solved it. Stupid question: where did you run xhost +local:root exactly?

Thank’s for any help.
Oskar

What do you mean with “where”?

I open Visual Studio and its terminal, in which I put all the commands.
I don’t know if Pycharm has a Docker extension, but in VS you can easily manage docker containers and run code inside the container itself.

If I didn’t understand your question please be more specific!

Antonio

Hey Antonio, thank’s for the quick reply. I think you did understand the question correctly. I work in a python IDE PyCharm and just found here that

Unfortunately, PyCharm doesn’t support X11 forwarding at this moment.

So is there any hope this might work within PyCharm as well?

I am sorry, but I don’t know a lot about Pycharm.