7

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?

Hugo Roussaffa
2,35617 silver badges44 bronze badges
asked Nov 21, 2021 at 14:17

2 Answers 2

5

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
answered Nov 25, 2022 at 9:32
0

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.

answered Mar 5 at 13:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.