如何将主机目录挂载到正在运行的Docker容器中 [英] How to mount a host directory into a running docker container

查看:107
本文介绍了如何将主机目录挂载到正在运行的Docker容器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将USB驱动器安装到正在运行的docker实例中,以手动备份某些文件.

I want to mount my usb drive into a running docker instance for manually backup of some files.

我知道 docker run -v 功能,但这会创建一个新容器.注意:它是nextcloudpi容器.

I know of the -v feature of docker run, but this creates a new container. Note: its a nextcloudpi container.

推荐答案

您只能更改

You can only change a very limited set of container options after a container starts up. Options like environment variables and container mounts can only be set during the initial docker run or docker create. If you want to change these, you need to stop and delete your existing container, and create a new one with the new mount option.

如果您认为需要保留或备份数据,则无论如何它都应该存在于某种卷装载中.删除并重新启动容器,并使用 -v 选项将卷安装在保存数据的位置.Docker文档提供了一个示例,该示例使用命名的卷具有单独的名称备份和还原容器;或者,您可以直接在其中使用主机目录和常规备份解决方案.(如我在第一段中建议的那样,删除和重新创建容器是非常常规的操作,不应包含明确的备份"和还原"步骤.)

If there's data that you think you need to keep or back up, it should live in some sort of volume mount anyways. Delete and restart your container and use a -v option to mount a volume on where the data is kept. The Docker documentation has an example using named volumes with separate backup and restore containers; or you can directly use a host directory and your normal backup solution there. (Deleting and recreating a container as I suggested in the first paragraph is extremely routine, and this shouldn't involve explicit "backup" and "restore" steps.)

如果您现在拥有无法承受的丢失数据,则可以

If you have data that's there right now that you can't afford to lose, you can docker cp it out of the container before setting up a more robust storage scheme.

这篇关于如何将主机目录挂载到正在运行的Docker容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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