linux - Shared volume/file permissions/ownership (Docker) -


i'm having annoying issue while using docker container (i'm on ubuntu, no virtualization vmware or b2d). i've built image, , have running container has 1 shared (mounted) directory host, , 1 shared (mounted) file host. here's docker run command in full:

docker run -dit \ -p 80:80 \ --name my-container \ -v $(pwd)/components:/var/www/components \ -v $(pwd)/index.php:/var/www/index.php \ my-image 

this works great, , both /components (and contents) , file shared appropriately. however, when want make changes either directory (e.g. adding new file or folder), or edit mounted file (or file in directory), i'm unable due incorrect permissions. running ls- lfh shows owner , group mounted items have been changed libuuid:libuuid. modifying either file or parent directory requires root permissions, impedes workflow (as i'm working sublime text, not terminal, i'm presented popup admin privs).

why occur? how can work around / handle properly? managing data volumes: mount host file data volume:

note: many tools used edit files including vi , sed --in-place may result in inode change. since docker v1.1.0, produce error such “sed: cannot rename ./sedkdj9dy: device or resource busy”. in case want edit mounted file, easiest instead mount parent directory.

this seem suggest instead of mounting /components , /index.php, should instead mount parent directory of both. sounds great in theory, based on behavior of -v option , how interacts /directory, seem every file in parent directory altered owned libuuid:libuuid. additionally, have lots of things inside parent directory not needed in container - things build tools, various files, compressed folders, etc. mounting whole parent directory seem wasteful.

running chown user:group on /components , /index.php on host machine allow me work around , seem continue sync container. i'll need every time run container mounted host volumes? i'm guessing there more efficient way this, , i'm not finding explanation particular use-case anywhere.

i using container development of module program, , have no desire manage data-only container - files matter host; persistence isn't needed elsewhere (like database, etc).

after creating image, run command i'm using:

docker run -dit \     -p 80:80 \     --name my-container \     -v $(pwd)/components:/var/www/wp-content/plugins/my-plugin-directory/components \     -v $(pwd)/index.php:/var/www/wp-content/plugins/my-plugin-directory/index.php \     my-image 

it looks chown -r nginx:nginx ... commands inside container changing ownership bits on files owned libuuid on host machine.

see understanding user file ownership in docker: how avoid changing permissions of linked volumes basic explanation on how file ownership bits work between host , docker containers.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -