xca icon indicating copy to clipboard operation
xca copied to clipboard

docker build gives warning

Open radoeka opened this issue 5 months ago • 2 comments

As Debian provides xca-2.8.0 I was curious to see if it was possible to obtain and run xca via docker. And yes there is a dockerfile and I could even build the container, kudos for this.

The docker build shows 2 warnings:

2 warnings found (use docker --debug to expand):

  • FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 4)
  • LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 6)

The first is easy to fix; change 'as' to 'AS':

--- Dockerfile  2025-03-28 19:28:15.000000000 +0100
+++ Dockerfile.new      2025-08-09 21:29:16.839057251 +0200
@@ -1,7 +1,7 @@
 ARG REGISTRY_PREFIX=''
 ARG CODENAME=noble
 
-FROM ${REGISTRY_PREFIX}ubuntu:${CODENAME} as builder
+FROM ${REGISTRY_PREFIX}ubuntu:${CODENAME} AS builder
 
 ENV DEBIAN_FRONTEND noninteractive

As I'm not familiair with Ubuntu, their codenames do not say me anything. As such would it be possible to extent this explanation a bit more (file INSTALL.docker):

Build options
-------------

There are some options to customize build. Use dockers "--build-arg"
option to add options.

CODENAME              : code name of ubuntu version
                        example: --build-arg CODENAME=jammy

My suggestion would be add at least add (on which Ubuntu (latest) version xca is known to be working The Dockerfile has Noble, and with the information above, it looks like that xca works on Noble (24.04) and Jammy (22.04). For convenience add a link to https://releases.ubuntu.com/ as this has a nice overview of the available released.

My docker file does not start

If I run the container as described in the INSTALL.docker file, it does not start.

$ docker run --rm -it -e USER_ID=`id -u` --network=host -e DISPLAY=$DISPLAY -e "QT_X11_NO_MITSHM=1" xca
using USER_ID from environment: 1000
useradd: UID 1000 is not unique
$ docker run --rm -it -e USER_ID=1234 --network=host -e DISPLAY=$DISPLAY -e "QT_X11_NO_MITSHM=1" xca
using USER_ID from environment: 1234
X11 connection rejected because of wrong authentication.
   000 Warning: could not connect to display localhost:10.0
   000 Info: Could not load the Qt platform plugin "xcb" in "" even though it was found.
   000 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: vnc, minimal, eglfs, offscreen, vkkhrdisplay, linuxfb, xcb, minimalegl.

Aborted

$ echo $DISPLAY
localhost:10.

Any suggestion what I can do, to get the container running in my environment?

I use Linux on my desktop (openSUSE), ssh (-X) into a raspberry PI, and started the command from there. Option 2) Logged into the raspberry PI via tightvnc. In that case I get the same the response (as the last one) above.

In tightvnc the DISPLAY is set to:

$ echo $DISPLAY
:0

What can I do to make the container work?? It would be great if this works.

radoeka avatar Aug 09 '25 19:08 radoeka

Update:

It works on tightvnc

Image

I had to use 'xhost +', to allow the container to write to my Xserver.

I suggest to add this to the INSTALL.docker guide.

Don't how to make this work if ssh is involved...

radoeka avatar Aug 09 '25 20:08 radoeka

I did some more experiments for starting xca from Docker.

I come to that in a minute, first it looks like there is small bug in the docker_start.sh file.

Read on before examing or changing anything.

The variable filepath has 2 versions 1 with and 1 without '_'. I propose to remove the 1 with _:

--- docker_start.sh.old	2025-08-10 13:38:42.010434039 +0200
+++ docker_start.sh	2025-08-10 13:39:18.114420563 +0200
@@ -4,7 +4,7 @@
 
 default_userid=1000
 
-file_path="/home/user/.Xauthority"
+filepath="/home/user/.Xauthority"
 
 if [ -n "$USER_ID" ]; then
     if [[ "$USER_ID" =~ ^[0-9]+$ ]] && [ "$USER_ID" -gt 0 ]; then

However, it may be easier altogether to use the following command, as this may obsolete docker_start.sh:

docker run --rm -it --volume $HOME/.Xauthority:/home/ubuntu/.Xauthority --volume /tmp/.X11-unix:/tmp/.X11-unix --env DISPLAY=$DISPLAY --env "QT_X11_NO_MITSHM=1" xca

( The X11 information was received from: https://www.baeldung.com/linux/docker-container-gui-applications )

Important difference the use of the already existing user ubuntu in the container. That was at least the case on Ubuntu with codename=plunky (version 25.04).

If the above becomes part of the code, the Dockerfile can be updated and the line for the creation of user user can be removed:

RUN mkdir -p /home/user && chmod 0777 /home/user

I would like to propose to add a script (xca-docker.sh) to simplify things for the user

#!/bin/bash

set -o nounset

PATH="/usr/bin"

# Allow the user ubuntu@docker to use the Xserver
# If the docker hostname is known, use 'xhost +<docker hostname>
xhost +
docker run --rm -it \
  --volume $HOME/.Xauthority:/home/ubuntu/.Xauthority --volume /tmp/.X11-unix:/tmp/.X11-unix \
  --env DISPLAY=$DISPLAY --env "QT_X11_NO_MITSHM=1" \
  xca
xhost -

In the Dockerfile, change the entrypoint to:

exec su ubuntu -c "xca $*"

If this is done, it will obsolete the file: misc/docker_start.sh

Summary:

  1. Update Dockerfile: to use Ubuntu codename=punky or higher
  2. Update Dockerfile: remove creation of user user
  3. Update Dockerfile: change entrypoint to: exec su ubuntu -c "xca $*"
  4. Add script xca-docker.sh that takes care of the X11 permissions
  5. Obsolete script misc/docker_start.sh?

After this, build the container image and start xca with: ./xca-docker.sh

Alternative start script (xca-docker.sh), no entrypoint in the Dockerfile needed anymore:

#!/bin/bash

set -o nounset

PATH="/usr/bin"

echo -- "$*"

# Allow the user ubuntu@docker to use the Xserver
# If the docker hostname is known, use 'xhost +<docker hostname>
xhost +
docker run --rm -it \
  --volume $HOME/.Xauthority:/home/ubuntu/.Xauthority --volume /tmp/.X11-unix:/tmp/.X11-unix \
  --env DISPLAY=$DISPLAY --env "QT_X11_NO_MITSHM=1" \
  xca-plucky-no-entrypoint \
  /bin/bash -c "su ubuntu -c xca $*"
xhost -

But, please test with one, with arguments. --help works, I don't know about other arguments.

radoeka avatar Aug 10 '25 12:08 radoeka