Can not change the permission and owner of directory create by root

[root@mycompany agent-mvn]# cat Dockerfile 

USER root

COPY apache-maven-3.9.1-bin.tar.gz .
RUN tar -zxf apache-maven-3.9.1-bin.tar.gz && \
     mv apache-maven-3.9.1 /usr/local && \
     rm -f apache-maven-3.9.1-bin.tar.gz && \
     ln -s /usr/local/apache-maven-3.9.1/bin/mvn /usr/bin/mvn && \
     ln -s /usr/local/apache-maven-3.9.1 /usr/local/apache-maven && \
     mkdir /home/jenkins/agent/repo && \
     chmod 666 /home/jenkins/agent/repo && \
     chown jenkins:jenkins /home/jenkins/agent/repo 

COPY settings.xml /usr/local/apache-maven/conf/settings.xml

USER jenkins
[root@mycompany ~]# kubectl exec -it -n jenkins jenkins-slave-f13fw-h47tt bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
jenkins@jenkins-slave-f13fw-h47tt:~/agent$ cd /home/jenkins/agent
jenkins@jenkins-slave-f13fw-h47tt:~/agent$ ls -l
total 0
drwxr-xr-x 4 jenkins jenkins 34 Apr 25 10:39 remoting
drwxr-xr-x 2 root    root     6 Apr 25 06:55 repo

Note that sharing only code and writing about the issue only in title will not attract many people to help. I checked the code anyway and I guess you are using a volume in Kubernetes so even if you replace the image, the old volume will be mounted with the old ownership. First you should try running a container from the newly built image locally without volumes and check the permissions there.

One other wy could be if the service inside the container “fixes” the permissions while starting the container.

I can’t think of ny other way right now.

PS.: I removed the other topic with the same content. The spam filter blocked this one until I allowed it.