Jenkins newbie - difficulty getting started

Created docker compose file with custom image build

services:
  jenkins:
    #    image: jenkins/jenkins:lts-jdk21
    image: jenkins-my-img:lts-jdk21
    build:
      context: .
      dockerfile: Dockerfile
    container_name: jenkins-server
    platform: linux/amd64
    ports:
      - "8080:8080"
      - "50000:50000"
    # user: "1000"
    # environment:
    #  - PUID=1000
    #  - PGID=1000
    volumes:
      - jenkins_home:/var/jenkins_home:rw
      # - ~/jenkins_config:/var/jenkins_home

#   agent:
#     image: jenkins/ssh-agent:jdk21
#     container_name: agent
#     privileged: true
#     expose:
#       - 22
#     environment:
#       - JENKINS_AGENT_SSH_PUBKEY=${SSH_PUB_KEY}
#     # user: root
#     volumes:
#       - agent_data:/home/jenkins/agent # For persistent agent data

volumes:
  jenkins_home:
#   agent_data:

Dockerfile:

(had to use custom docker image to install recommended plugins because plugins do not install due to some issue with Java cert store!)

FROM jenkins/jenkins:lts-jdk21
USER root
RUN apt-get update && apt-get install -y ca-certificates && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

RUN update-ca-certificates

RUN jenkins-plugin-cli --plugins "timestamper ant gradle git ldap mailer github-branch-source ws-cleanup build-timeout credentials-binding pipeline-github antisamy-markup-formatter ssh-agent matrix-auth email-ext pipeline-graph-view pipeline-github-lib dark-theme workflow-aggregator ssh-slaves pam-auth"

USER jenkins

Created Pipeline and ran on jenkins server with issues (file permissions?):

[Security Scan] ERROR: An exception occurred while writing into json file: Failed to create a temp file on /var/jenkins_home/workspace
[Security Scan] ERROR: Workflow failed! Exit code 999: Undefined plugin error - Cannot invoke "String.concat(String)" because "arg" is null

Does the same when try on an ssh agent. Hello world pipeline works.

The pipeline I am running downloads an external CLI utility that tries to write files in the workspace. How do I give it permission? OR is the issue docker compose volume permission?

Any ideas as to how to get jenkins pipelines working and building in docker compose stack?

I believe you have to run the jenkins-plugin-cli tool from the Jenkins user, so in your dockerfile you probably get a bunch of root-owned plugins together, maybe with some additional metadata files that confuse Jenkins further.
In addition, I also suggest to check the ownership of everything else in the jenkins_home volume, in case you accidentally got some more leftovers from root.

But the best practice is to set the executors count on your controller to 0, avoid running pipelines in there altogether, and provide some external agents instead – preferably on a separate machine even, to avoid loads from pipelines affecting the controller itself.

Thanks @Artalus thats a very good point regarding running the jenkins-plugin-cli from the Jenkins user in the docker build. I updated the Dockerfile and tried it but still getting the same issue

Yeah I tried running the build on external agent (agent docker compose service - commented) but get the same issue. Haven’t tried on external machine though since unavailable