将数据添加到 Docker 中现有命名卷的正确方法是什么? [英] What is the right way to add data to an existing named volume in Docker?

查看:15
本文介绍了将数据添加到 Docker 中现有命名卷的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以旧方式使用 Docker,带有一个卷容器:

I was using Docker in the old way, with a volume container:

docker run -d --name jenkins-data jenkins:tag echo "data-only container for Jenkins"

但现在我通过创建命名卷更改为新方式:

But now I changed to the new way by creating a named volume:

 docker volume create --name my-jenkins-volume 

我将这个新卷绑定到一个新的 Jenkins 容器.我唯一留下的是一个文件夹,其中包含我以前的 jenkins 容器的 /var/jenkins_home.(通过使用 docker cp)现在我想用该文件夹的内容填充我的新命名卷.

I bound this new volume to a new Jenkins container. The only thing I've left is a folder in which I have the /var/jenkins_home of my previous jenkins container. (by using docker cp) Now I want to fill my new named volume with the content of that folder.

我可以将该文件夹的内容复制到 /var/lib/jenkins/volume/my-jenkins-volume/_data 吗?

Can I just copy the content of that folder to /var/lib/jenkins/volume/my-jenkins-volume/_data?

推荐答案

可以当然可以将数据直接复制到 /var/lib/docker/volumes/my-jenkins-volume/_data,但这样做你是:

You can certainly copy data directly into /var/lib/docker/volumes/my-jenkins-volume/_data, but by doing this you are:

  • 依赖对docker主机的物理访问.如果您正在与远程 docker api 交互,则此技术将不起作用.

  • Relying on physical access to the docker host. This technique won't work if you're interacting with a remote docker api.

依赖卷实施的特定方面可能会在未来发生变化,从而破坏您拥有的任何依赖它的流程.

Relying on a particular aspect of the volume implementation would could change in the future, breaking any processes you have that rely on it.

我认为你最好依靠你可以通过命令行客户端使用 docker api 完成的事情.最简单的解决方案可能只是使用辅助容器,例如:

I think you are better off relying on things you can accomplish using the docker api, via the command line client. The easiest solution is probably just to use a helper container, something like:

docker run -v my-jenkins-volume:/data --name helper busybox true
docker cp . helper:/data
docker rm helper

这篇关于将数据添加到 Docker 中现有命名卷的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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