Docker volume: File owner set to root when created from host machine

116 Views Asked by At

I have a directory in my Docker contains which is mounted to a dir on the host OS. Sometimes, when I create a file in that directory from within host OS as a non-root, in the container, it shows owner is "root". How can I make sure all files I create will be non-root? Or at least allow read/write for non-root user inside the dir?

My Dockerfile: VOLUME /home/mahdix/command My command line: docker run -v "$(pwd)"/command:/home/mahdix/command ...

on the host OS, as a normal user: goto /command -> vim test -> make some changes -> save and exit

inside the container, when I list files in the "/home/mahdix/command" directory, they belong to root:root.

I'm running these inside Mac OS. The base image is Ubuntu:22.04.

0

There are 0 best solutions below