Running Docker container - X11 failed to open display :0

I have a project written in Golang using the Fyne framework. I am aware of the issues that are related to X11 when trying to Dockerize these type of applications. Here is my Dockerfile:

FROM golang:1.20


COPY . .

RUN go mod download
RUN apt-get update && apt-get install -y libgl1-mesa-dev xorg-dev x11-apps dbus-x11 xvfb make
RUN make

# my Golang app takes in a single command line argument hence the ENTRYPOINT.
# specifically, the command line argument is an address the application will use.
ENTRYPOINT ["./cmd/server/server"]

Here is how I am running it: docker run -e DISPLAY=$DISPLAY -p 8080:3000 --net=host red "localhost:3000"

However, this seems to cause the error:

PlatformError: X11: Failed to open display :0
panic: NotInitialized: The GLFW library is not initialized

I am also aware of the available fyne-cross project. I attempted to use that and ran into more problems as well. I would like to try Dockerize this project myself however.

I've tried doing xhost + local:docker (I know, not secure) however the same error pops up. I have also tried: docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix red "localhost:3000" I've also tried with and without the --net=host. I saw this solution in another post but it didn't seem to do anything. For context, I am on Ubuntu.


  • To my knowledge X11 forwarding does not expose the OpenGL driver necessary to run a Fyne application. This is similar to the open issue that a Fyne app cannot be launched from headless Linux.