简体   繁体   中英

Copy and chown files into a docker bind mount at runtime

I have nginx and wordpress in docker containers, which share a volume bind mount (ie mapped to files on disk) for /var/www/html .

At runtime I need to add files to the mapped directory, chown them, and for them to be usable. They appear in the volume, but their owner is wrong so they are unusable by nginx / wordpress.

(Typically the advice is to do this in the Dockerfile - but that doesn't apply in this case. I'm not modifying the app, I'm just adding to the volume, which is not ephemeral.)

When I stop and start the docker apps (nginx and wordpress), everything works. But it doesn't work while online.

The parent directory has chmod 2775 and chown -R bob:www-data . When I copy files in there at runtime, I am doing so as bob . But nginx still cannot access those new files (404).

So how do I copy and chown files into a bind mount at runtime?

You should check that you are not only using the same username, but also the same UID & GID (If you have the user bob both in docker and the host but UID & GID don't match you will get permissions issues).

There is a good explanation on that on this other post .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM