Copy files from docker to host when mounting

巧了我就是萌 提交于 2020-03-05 05:29:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!