Change ownership when copying files in Docker
Sometimes you need to make changes to ADD-ed or COPY-ied files from Docker container processes. In these cases you may need to make something like:
COPY . /app-root
RUN chown -R myuser /app-root
This means you have to iterate twice over all files in /app-root, which may add a few seconds to every build for big hierarchies.
As of Docker 17.09, you can finally replace the chown command with a dedicated flag for COPY:
COPY --chown=myuser . /app-root
The same flag works for ADD. More information can be found in the PR. Unfortunately, chmod is not supported yet.