I built your image and tried to run it – it immediately exits. I don’t think what you’re doing is valid, is the problem. The container logs look like this:
docker container logs c5425a94419f1a9f
OpenJDK 64-Bit Server VM warning: Unable to get SVE vector length on this system. Disabling SVE. Specify -XX:UseSVE=0 to shun this warning.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.035 s
[INFO] Finished at: 2025-10-12T19:23:21Z
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: pre-clean, clean, post-clean, validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
OK, apparently the docker agent doesn’t need to be persistent. I observe that -u jenkins does not work with sh; can’t really tell you why. You may want to look at the Jenkins log to see if your output indicates what’s going on both in the -u jenkins and -u root cases.
I’ve done a bit on analysis on this, and my suspicious is that the mvn base image you’re using does not like running as non-root, based on errors I see when doing exec for various tasks on the image. So a couple of questions for you: