I am trying to create container and load QGIS GUI from qgis/qgis docker image. But unfortunately I am faced with this error on running the following command :
C:\Users\spa> docker run --rm -it -e DISPLAY=$DISPLAY qgis/qgis /bin/bash
root@a51412bc8744:/# qgis
Warning: could not connect to display
Info: Could not load the Qt platform plugin "xcb" in "" even though it was found.
Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
QGIS died on signal -1 Aborted
root@a51412bc8744:/#
I am trying to install the plugins with sudo apt-get eglfs
but that results an error.
So how do you run QGIS GUI application inside a docker container?
2 Answers 2
You need to export your current user and X-window environment correctly, which including you have to using the same user id, share .X11-unix socket and .XAuthority. Also you need to let the user have permission to its home inside docker.
The example working docker run command shows below, where assume your host user id = 1000, and home dir is set to /home/user, then you need to mount your /etc/passwd, a working folder mount as /home/user (to make the user and user home exists in the docker), also the X11-unix and XAuthority like
docker run --rm -it -u 1000 -e DISPLAY=$DISPLAY -v /etc/passwd:/etc/passwd:ro -v $PWD:/home/user -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/home/user/.Xauthority qgis/qgis:release-3_28 /bin/bash
Update: you can also this command to extract user id and home dir from shell directly, which should work in most of enviroment
docker run --rm -it -u $UID -e DISPLAY=$DISPLAY -v /etc/passwd:/etc/passwd:ro -v $PWD:$HOME -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:$HOME/.Xauthority qgis/qgis:release-3_28 /bin/bash
As the simplest way I have found is to use docker compose. setting up Display VNC port and volume for X11.
with that config I get QGIS dev runing strait on my host.
create the docker compose yaml file :
services:
qgis:
image: qgis/qgis:latest
container_name: qgis-container
environment:
- DISPLAY=:1
ports:
- "5901:5901" # VNC port
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix # X11 communication
- ./data:/data
network_mode: "host" # use host network (to facilitate VNC acces)
shm_size: 2gb
command: ["bash", "-c", "x11vnc -forever -display :1 & qgis"]
extra_hosts:
- "host.docker.internal:host-gateway"
and run it:
docker compose up -d
then, next time, you can start your container to get QGIS run.