[英]docker-compose using volume from exisiting container
New to docker and docker-compose, have written compose file that starts couple of services one of which relies on mongo database. 对于docker和docker-compose来说是新手,已经编写了compose文件,该文件启动了几个服务,其中一项依赖于mongo数据库。 I downloaded mongo image a while back and loaded it with data in a container. 我不久前下载了mongo映像,并在容器中加载了数据。 When I start my mongo instance up via docker-compose starts a new container based on empty image so don't get the data. 当我通过docker-compose启动mongo实例时,将基于空图像启动一个新容器,因此不要获取数据。
Been reading about volumes as a way of trying to get compose to use the data from the existing container and have tried several permutations now and just can't get it to find the data. 一直在阅读有关卷的信息,这是一种尝试使用现有容器中的数据进行组合的方法,并且现在已经尝试了几种排列方式,但无法通过它来查找数据。
When I start the container with the data and do inspect I get : 当我使用数据启动容器并进行检查时,我得到:
"Mounts": [
{
"Type": "volume",
"Name": "3f78b88e3e06f31d5f65a45bb1cb964245551875218d065162625cc73e662b1e",
"Source": "/var/lib/docker/volumes/3f78b88e3e06f31d5f65a45bb1cb964245551875218d065162625cc73e662b1e/_data",
"Destination": "/data/configdb",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Type": "volume",
"Name": "d3f89470c9f8c53b55c30338f691eb1586600343004c502feffe8f81091d7d5c",
"Source": "/var/lib/docker/volumes/d3f89470c9f8c53b55c30338f691eb1586600343004c502feffe8f81091d7d5c/_data",
"Destination": "/data/db",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
So am I right in saying I need to somehow get new container to use these mount points using volume tag ? 那么我是说对了吗,我需要以某种方式获得新的容器,以便通过volume标签使用这些安装点?
Have tried: 试过:
volumes:
- type: volume
source: /var/lib/docker/volumes/3f78b88e3e06f31d5f65a45bb1cb964245551875218d065162625cc73e662b1e/_data
target: /data/configdb
volume:
nocopy: true
- type: volume
source: /var/lib/docker/volumes/d3f89470c9f8c53b55c30338f691eb1586600343004c502feffe8f81091d7d5c/_data
target: /data/db
volume:
nocopy: true
and : 和:
volumes:
- /data/configdb:/var/lib/docker/volumes/3f78b88e3e06f31d5f65a45bb1cb964245551875218d065162625cc73e662b1e/_data
- /data/db:/var/lib/docker/volumes/d3f89470c9f8c53b55c30338f691eb1586600343004c502feffe8f81091d7d5c/_data
But to be honest grasping at straws, any help in an example of what I should be doing to use the exisiting data would be much appreciated. 但是说实话,任何帮助我举例说明如何使用现有数据的方法将不胜感激。
Lawrence 劳伦斯
Assuming you are using Compose file format v3.0+, try change the type
option to bind
in your volumes definition. 假设您使用的是Compose文件格式v3.0 +,请尝试更改type
选项以bind
到卷定义中。 The difference is that for volume
type, when provided, the source
refers to the name of named volume. 区别在于,对于volume
类型,提供时, source
引用命名卷的名称。 For bind
, the source
refers to the path to the file or directory on the Docker daemon host. 对于bind
, source
是指Docker守护程序主机上文件或目录的路径。
You can read more about the different types of mount in the Docker documentation . 您可以在Docker 文档中了解有关不同类型的安装的更多信息。
Try the following: 请尝试以下操作:
volume create data_storage
使用volume create data_storage
名称volume create data_storage
docker run -d -v data_storage:/data/db --name mongoding mongo
用卷docker run -d -v data_storage:/data/db --name mongoding mongo
Kill the container and start a new one to see it working. 杀死容器并启动一个新容器,以查看其是否正常工作。
docker container inspect 708bf6fe0a5b 码头集装箱检查708bf6fe0a5b
"Mounts": [ { "Type": "volume", "Name": "data_storage", "Source": "/var/lib/docker/volumes/data_storage/_data", "Destination": "/data/db", "Driver": "local", "Mode": "z", "RW": true, "Propagation": "" },
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.