Ideally the build script/docker image should set the $USER executing the build as owner of build file. Related "issue" and possible workarounds: https://github.com/moby/moby/issues/22258