Using pyvista meeting error when using docker

I try to use Dolfinx in docker to run codes.However, when I try to plot them using Pyvista, I encounter the error

X Error of failed request:  BadShmSeg (invalid shared segment parameter)
  Major opcode of failed request:  130 (MIT-SHM)
  Minor opcode of failed request:  3 (X_ShmPutImage)
  Segment id in failed request:  0x600005
  Serial number of failed request:  67
  Current serial number in output stream:  68

and I don’t know why. If I delete the part involving Pyvista, the code runs well and I also try other codes written before and they can be compiled well.So maybe something wrong with the codes when I use pyvista. I am new to docker too, so I don’t know whether the error is from docker or pyvista.
Please help me with it. Thanks in advance!
The code is given below

from dolfinx import mesh, fem,plot,io
from functools import partial
from ufl import (inner, dot, div, grad,
                 TrialFunction, TestFunction, dx,ds,FacetNormal,
                 CellDiameter, min_value, sqrt, lhs, rhs, SpatialCoordinate, exp,Measure
                 )
from mpi4py import MPI
from petsc4py import PETSc
import numpy as np

Nx=20
Ny=20
k=1


domain=mesh.create_unit_square(MPI.COMM_WORLD,Nx,Ny)
V=fem.FunctionSpace(domain,("CG",k))

f=fem.Constant(domain,PETSc.ScalarType(0))
a=fem.Constant(domain,np.array([np.cos(np.arctan(1)),np.sin(np.arctan(1))],dtype=PETSc.ScalarType))
kappa=fem.Constant(domain,PETSc.ScalarType(1e-6))

boundary_zero=fem.Constant(domain,PETSc.ScalarType(0))
boundary_one=fem.Constant(domain,PETSc.ScalarType(1))

boundaries=[(1,lambda x:np.logical_and(np.isclose(x[0],0),np.logical_and(x[1]>0.2-1e-16,x[1]<=1))),
            (2,lambda x:np.logical_and(np.isclose(x[0],0),np.logical_and(x[1]<0.2+1e-16,x[1]>=0))),
            (3,lambda x:np.isclose(x[1],0)),
            (4,lambda x:np.isclose(x[0],1)),
            (5,lambda x:np.isclose(x[1],1))]
facet_indices,facet_markers=[],[]
fdim=domain.topology.dim-1
for (marker,locator) in boundaries:
    facets=mesh.locate_entities(domain,fdim,locator)
    facet_indices.append(facets)
    facet_markers.append(np.full_like(facets,marker))
facets_indices=np.hstack(facet_indices).astype(np.int32)
facets_markers=np.hstack(facet_markers).astype(np.int32)
sorted_facets=np.argsort(facets_indices)
facet_tag=mesh.meshtags(domain,fdim,facets_indices[sorted_facets],facets_markers[sorted_facets])

u=TrialFunction(V)
v=TestFunction(V)

h=CellDiameter(domain)
tau=h/2

facet_zero=np.hstack([facet_tag.find(1),facet_tag.find(4),facet_tag.find(5)])
dofs_zero = fem.locate_dofs_topological(V, fdim, facet_zero)
bcd0=fem.dirichletbc(boundary_zero,dofs_zero,V)

facet_one=np.hstack([facet_tag.find(2),facet_tag.find(3)])
dofs_one = fem.locate_dofs_topological(V, fdim, facet_one)
bcd1=fem.dirichletbc(boundary_one,dofs_one,V)

bcd=[bcd0,bcd1]

A=dot(a,grad(u))*v*dx+kappa*dot(grad(u),grad(v))*dx+ \
    tau*(-kappa*div(grad(u))+dot(a,grad(u)))*(dot(a,grad(v))+kappa*div(grad(v)))*dx
L=f*v*dx+f*tau*(dot(a,grad(v))+kappa*div(grad(v)))*dx

problem=fem.petsc.LinearProblem(A,L,bcs=bcd)

uh=fem.Function(V)

uh=problem.solve()

import pyvista as pv

plotter=pv.Plotter()

grid=pv.UnstructuredGrid(*plot.create_vtk_mesh(V))

grid.point_data["uh"]=uh.x.array
grid.set_active_scalars("uh")
warped = grid.warp_by_scalar("uh", factor=0.1)

plotter.add_mesh(warped,show_edges=True)

plotter.view_xy()

plotter.show()

Pyvista needs a virtual frame buffer if used in docker. (pyvista.start_xvfb).
https://docs.pyvista.org/extras/docker.html
For instance, if you want to run your docker container on linux, I would use the following arguments:

docker run -ti --network=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $(pwd):/root/shared -w /root/shared --rm -v /dev/dri:/dev/dri --entrypoint=/bin/bash  dolfinx/lab:v0.6.0-r1

On your system, add:

xhost si:localuser:root

and for instance run the code:

import numpy as np

import pyvista as pv
pv.OFF_SCREEN = False

ni, nj, nk = 4, 5, 6
si, sj, sk = 20, 10, 1

xcorn = np.arange(0, (ni + 1) * si, si)
xcorn = np.repeat(xcorn, 2)
xcorn = xcorn[1:-1]
xcorn = np.tile(xcorn, 4 * nj * nk)

ycorn = np.arange(0, (nj + 1) * sj, sj)
ycorn = np.repeat(ycorn, 2)
ycorn = ycorn[1:-1]
ycorn = np.tile(ycorn, (2 * ni, 2 * nk))
ycorn = np.transpose(ycorn)
ycorn = ycorn.flatten()

zcorn = np.arange(0, (nk + 1) * sk, sk)
zcorn = np.repeat(zcorn, 2)
zcorn = zcorn[1:-1]
zcorn = np.repeat(zcorn, (4 * ni * nj))

corners = np.stack((xcorn, ycorn, zcorn))
corners = corners.transpose()
dims = np.asarray((ni, nj, nk)) + 1
grid = pv.ExplicitStructuredGrid(dims, corners)
grid = grid.compute_connectivity()
plotter = pv.Plotter()
plotter.add_mesh(grid, show_edges=True)

if pv.OFF_SCREEN:
    pv.start_xvfb()
    plotter.screenshot("test.png")
else:
    plotter.show()

If you set pv.OFF_SCREEN=True, you can just run

docker run -ti  -v $(pwd):/root/shared -w /root/shared --rm --entrypoint=/bin/bash  dolfinx/lab:v0.6.0-r1

but make sure to start the xvfb before any screenshots are taken.

Thank you very much.