Change owner of files created inside a Docker container without changing the Dockerfile
No need to change the Dockerfile. Just define a certain user, e.g. jenkins and a certain uid, e.g. 1000 and ensure the same uid is used when a folder is mounted.


ARG user=jenkins
ARG uid=1000

# Jenkins is run with user `jenkins`, uid = 1000
# If you bind mount a volume from the host or a data container,
# ensure you use the same uid
RUN mkdir -p $JENKINS_HOME \
    &amp;&amp; chown ${uid}:${gid} $JENKINS_HOME \
    &amp;&amp; addgroup -g ${gid} ${group} \
&amp;&amp; adduser -h "$JENKINS_HOME" -u ${uid} -G ${group} -s /bin/bash -D ${user}

RUN chown -R ${user} "$JENKINS_HOME" /usr/share/jenkins/ref



https://github.com/jenkinsci/docker/blob/master/Dockerfile-alpine