Docker creates files as root in mounted volume [duplicate]

You could try to create (in the Dockerfile of a custom image) a user and set it as the one used by the container

RUN adduser --system --group --shell /bin/sh auser \
 && mkdir /home/auser/bin
USER auser

Then check if a docker run -v /home/matt/build:/build build-rpm mounts the shared folder in /build as auser.


Another option mentioned in issue 2259:

If you chown the volume (on the host side) before bind-mounting it, it will work.
In that case, you could do:

mkdir /tmp/www
chown 101:101 /tmp/www
docker run -v /tmp/www:/var/www ubuntu stat -c "%U %G" /var/www

(Assuming that 101:101 is the UID:GID of the www-data user in your container.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)