问题
I have a volume setup like this:
volumes:
- type: bind
source: //c//Docker/themes
target: /var/www/html/wp-content/themes
It works but when I create this mount it deletes all the files that were on the docker in specified path.
Is there an option or way to preserve those files and copy them to the host?
回答1:
Mounting does not delete the data that exist on the destination path, it hides it until you remove the mount point you will find the old data still exist. Think of it as the old data exist beneath the new volume that you have mounted
For example if you have wp-content/uploads/ on the main hard disk and for some reason you decided to have a separate disk for the upload. If you mounted the new hard disk directly which points to the upload path, it will hide the old files but wont delete them which is why you need to migrate the data first before mounting.
So I usually copy the content from the container first - if needed - to the host then i do the mounting part. So you can use this command first (I assume you are on windows - because of //c part - as I am not a windows user so you might need to change the path as needed):
docker cp mycontainer:/var/www/html/wp-content/themes //c//Docker/themes
After this you can mount the host directory which will contain everything. but make sure you don't have similar directories on the host before copying to avoid overriding the data.
来源:https://stackoverflow.com/questions/56893439/copy-files-from-docker-to-host-when-mounting