如何将卷添加到现有的Docker容器? [英] How can I add a volume to an existing Docker container?

查看:385
本文介绍了如何将卷添加到现有的Docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Docker容器,我通过在Ubuntu上安装Docker来创建一个Docker容器:

  sudo docker run  - i -t ubuntu / bin / bash 

我马上开始安装Java和其他一些工具,花一些时间与它并通过

  exit 

然后我想添加一个卷,意识到这并不像我以为会那么简单。如果我使用 sudo docker -v / somedir run ... 然后我最终得到一个新的新容器,所以我会安装Java并做我已经完成之前,才能到达带有安装卷的容器。



所有关于从主机安装文件夹的文档似乎都意味着安装卷可以是在创建容器时完成因此,我必须避免从头开始重新配置新容器的唯一选择是将现有容器提交到存储库,并将其用作新的容器的基础。



这是确实是向现有容器添加卷的唯一方法吗?

解决方案

现在是的,唯一的方法是娱乐请参阅 Docker Pull Request 8484 ,以便我们期待动态添加功能。


I have a Docker container that I've created simply by installing Docker on Ubuntu and doing:

sudo docker run -i -t ubuntu /bin/bash

I immediately started installing Java and some other tools, spend some time with it and stopped the container by

exit

Then I wanted to add a volume and realised that this is not as straightforward as I thought it would be. If I use sudo docker -v /somedir run ... then I end up with a fresh new container, so I'd have install Java and do what I've already done before just to arrive at a container with a mounted volume.

All the documentation about mounting a folder from the host seems to imply that mounting a volume is something that can be done when creating a container. So the only option I have to avoid reconfiguring a new container from scratch is to commit the existing container to a repository and use that as the basis of a new one whilst mounting the volume.

Is this indeed the only way to add a volume to an existing container?

解决方案

For now yes, the only way is recreation. See Docker Pull Request 8484 for when we can expect the dynamic adding functionality.

这篇关于如何将卷添加到现有的Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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