Mount volume to host
Asked Answered
A

4

16

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:/'.
Aurelie answered 17/3, 2016 at 7:22 Comment(0)
N
8

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.

Navarra answered 17/3, 2016 at 7:57 Comment(9)
What i'm trying to achieve actually is to expose all the files from container's / path to the Host, is it possible? I do know to mount a single directory but that's not really what I want.Aurelie
No that's not possible...container has some files which cannot be exposed as you don't have root access inside container.Navarra
hmm i guess this is a bad question then :\ i wish to expose all the files to host so that i can edit them easily using IDE or stuff like that.. I guess I'm down to mounting directories thenAurelie
Why would you need root folder for doing all that. If you create project in folder project and then create same directory inside container, copy all files and expose a volume you will be able to do exactly what you want.Navarra
Yup, thanks. I just wanted to justify the question above if it's achievableAurelie
@Navarra I am having the same problem as the OP, but slightly different environment. I have Windows 2016 as host system and running docker directly (with a Windows container). In my case, the folder on the guest does exist, but I am still getting the error as mentioned here in this post. (It works fine when I use a Ubuntu container, but having trouble with Windows): superuser.com/questions/1051520/… Do you have by any chance have an idea for this case? I could imagine it's still a bug in the Win2016 preview.Tycoon
I will check it on your question page and see if I can help ;)Navarra
The link is broken.Saltigrade
perhaps the link is broken because the Docker people don't give a damn about their users, or even backwards compatibility. @PeterMortensen, why can't they create URLs that don't change?Cattier
O
2

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.

Ossification answered 27/9, 2016 at 18:40 Comment(2)
On what platform is docker run? Linux?Saltigrade
I am running docker on Windows 7.Ossification
H
1

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
Hemichordate answered 3/4, 2022 at 19:34 Comment(0)
A
0

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.

Abattoir answered 11/10, 2021 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.