Mount volume to host

Viewed 15780

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:/'.
4 Answers

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.

Since you cant mount "/" one option is to add a "WORKDIR" to your Dockerfile, that way all subsequent commands will be relative to that dir and you wont have to modify anything!

FROM python:latest
WORKDIR /myapp
COPY appfile.py appfile.py

In your docker image, the "appfile.py" file will be in the /myapp/appfily.py location.

You cannot specify the '/' root directory of container but you can mount all the folders in to docker volumes present in root directory.....

create volumes by running these command one by one or you can create bash script

docker volume create var

docker volume create usr

docker volume create tmp

docker volume create sys

docker volume create srv

docker volume create sbin

docker volume create run

docker volume create root

docker volume create proc

docker volume create opt

docker volume create mnt

docker volume create media

docker volume create libx32

docker volume create lib64

docker volume create lib32

docker volume create lib

docker volume create home

docker volume create etc

docker volume create dev

docker volume create boot

docker volume create bin 

Then run this command

docker run -it -d \
--name=ubuntu-container \
--mount source=var,destination=/var \
--mount source=usr,destination=/usr \
--mount source=tmp,destination=/tmp \
--mount source=sys,destination=/sys \
--mount source=srv,destination=/srv \
--mount source=sbin,destination=/sbin \
--mount source=run,destination=/run \
--mount source=root,destination=/root \
--mount source=opt,destination=/opt \
--mount source=mnt,destination=/mnt \
--mount source=media,destination=/media \
--mount source=libx32,destination=/libx32 \
--mount source=lib64,destination=/lib64 \
--mount source=lib32,destination=/lib32 \
--mount source=lib,destination=/lib \
--mount source=home,destination=/home \
--mount source=etc,destination=/etc \
--mount source=boot,destination=/boot \
--mount source=bin,destination=/bin \
ubuntu:latest
Related