Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mount volume to host

I am currently using Boot2Docker on Windows. Is it possible to mount root to host?

Say that I'm using an Ubuntu image and I would like to mount / to the host. How can I do so?

I've been looking around and trying:

docker run -v /c/Users/ubuntu:/ --name ubuntu -dt ubuntu

But I ended up with an error:

docker: Error response from daemon: Invalid bind mount spec "/c/Users/ubuntu:/": volumeslash: Invalid specification: destination can't be '/' in '/c/Users/Leon/ubuntu:/'.
like image 331
Leon Avatar asked Mar 17 '16 07:03

Leon


2 Answers

If I understand correctly, you are trying to mount root inside a container as a volume? If that is the case, rather create a new directory inside and expose that one.

For example, dockerfile:

RUN mkdir /something
VOLUME /something

As the Docker documentation says, the container directory must always be an absolute path such as /src/docs. The host-dir can either be an absolute path or a name value.

For more information read this: https://docs.docker.com/engine/userguide/containers/dockervolumes/#mount-a-host-directory-as-a-data-volume and part "Mount a host directory as a data volume" should give you better understanding.

like image 119
Prototype Avatar answered Nov 05 '22 02:11

Prototype


It's the problem with how you are specifying the path. See the example of mounting a local volume to be used by a container for MongoDB:

docker run --name *container-name* -v **/Users/SKausha3/mongo/imageservicedb/data**:/*data* -v **/Users/SKausha3/mongo/imageservicedb/backup**:/*backup*

c:/Users/SKausha3/mongo/imageservicedb/data is my local folder, but you have to remove 'c:' from the path.

like image 2
SarveshKaushal Avatar answered Nov 05 '22 00:11

SarveshKaushal