挂载时将文件从Docker复制到主机 [英] Copy files from docker to host when mounting

查看:50
本文介绍了挂载时将文件从Docker复制到主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的音量设置:

volumes:
  - type: bind
    source: //c//Docker/themes
    target: /var/www/html/wp-content/themes

它可以工作,但是当我创建此挂载时,它将删除docker中指定路径上的所有文件.

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?

推荐答案

安装不会删除目标路径上存在的数据,而是将其隐藏,直到您删除安装点,您会发现旧数据仍然存在.可以将其视为已挂载的新卷下的旧数据

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

例如,如果您在主硬盘上具有 wp-content/uploads/,并且由于某种原因,您决定使用单独的磁盘进行上载.如果您直接装入指向上载路径的新硬盘,它将隐藏旧文件,但不会删除它们,这就是为什么在挂载之前需要首先迁移数据的原因.

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.

因此,通常我通常先将容器中的内容(如果需要)复制到主机,然后再进行安装.因此,您可以首先使用此命令(由于//c 部分,我假设您在Windows上-由于我不是Windows用户,因此您可能需要根据需要更改路径):

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.

这篇关于挂载时将文件从Docker复制到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆