Map data container volume to volume

981 views Asked by At

I am using the (not official, as mentioned by Usman) mongodb image (https://registry.hub.docker.com/u/dockerfile/mongodb/) which creates a volume at "/data/db"

create mongdb container:

docker build -t="dockerfile/mongodb" github.com/dockerfile/mongodb

Run data container:

docker run -v /data/db --name databox ubuntu:latest true

run mongdb container with the data container (write mongo data into data container)

docker run -d -p 27017:27017 --volumes-from databox --name mongodb_shared_persistence dockerfile/mongodb

I tested it with:

docker run --volumes-from=databox busybox ls /data/db

...db files are created. So far so good.

But what if the data container has a volume at /mongodb/data and I want to map that to the /data/db volume of the mongodb container?

...like this:

docker run -d -p 27017:27017 -v <?data_container_volume?>:/data/db --name mongodb dockerfile/mongodb

is that even possible?

1

There are 1 answers

2
Usman Ismail On BEST ANSWER

If you read the comments by shykes on Issue 111:

Volumes don't have top-level names. At no point does the user provide a name, or is a name given to him. Volumes are identified by the path at which they are mounted inside their container.

So I don't think there is any way to achieve this.