Mounting volumes as non-root user

I’m using a docker pipeline, and mounting a directory on the host to copy build artifacts to-

volumes:
  - name: build
    host:
      path: /some-folder

Unfortunately all the files that I copy to this volume end up being owned by root with ocal permissions of 022, which isn’t very useful when that folder is being served by NGINX.

Is there a way to specify the host user that the pipeline is executed under or change the permissions files written to the volume will have?

Thinking on this a bit more I think I might just be trying to shoehorn docker into a scenario that the exec pipeline is intended to be the solution to.

Ended up rewriting my config to use that instead, although I’d still be interested to know if the aforementioned configuration options exist!

It’s been years since I researched this particular issue, but last I checked it was not possible to mount docker volumes as non-root users. It looks like the relevant issue is still open: https://github.com/moby/moby/issues/2259

Alright, good to know! I guess for deploying files that non-root users will be accessing/running, the only option will be exec pipelines then. :grin:

Alright, good to know! I guess for deploying files that non-root users will be accessing/running, the only option will be exec pipelines then

docker cannot mount a volume as non-root, but you can always chown the volume or its contents after it has been mounted.

1 Like