Skip to content

Instantly share code, notes, and snippets.

@johannespetzold
Last active August 29, 2015 14:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johannespetzold/05b2fc00793a6ec0b0d6 to your computer and use it in GitHub Desktop.
Save johannespetzold/05b2fc00793a6ec0b0d6 to your computer and use it in GitHub Desktop.
boot2docker stop
VBoxManage sharedfolder add boot2docker-vm -name workspace -hostpath $HOME/workspace
boot2docker up
boot2docker ssh "sudo modprobe vboxsf && sudo mkdir -p $HOME/workspace && sudo mount -t vboxsf -o umask=0022,gid=50,uid=1000 workspace $HOME/workspace"
#!/bin/bash -ex
export DOCKER_HOST=tcp://$(boot2docker ip 2>/dev/null):2375
docker build -t my-boot2docker-img .
docker run --rm my-boot2docker-img > boot2docker.iso
FROM boot2docker/boot2docker
RUN apt-get -y install p7zip-full
ENV VBOX_VERSION 4.3.12
# Build VBox guest additions
RUN mkdir -p /vboxguest && \
cd /vboxguest && \
curl -L -o vboxguest.iso http://download.virtualbox.org/virtualbox/${VBOX_VERSION}/VBoxGuestAdditions_${VBOX_VERSION}.iso && \
7z x vboxguest.iso -ir'!VBoxLinuxAdditions.run' && \
sh VBoxLinuxAdditions.run --noexec --target . && \
mkdir x86 && cd x86 && tar xvjf ../VBoxGuestAdditions-x86.tar.bz2 && cd .. && \
mkdir amd64 && cd amd64 && tar xvjf ../VBoxGuestAdditions-amd64.tar.bz2 && cd .. && \
cd amd64/src/vboxguest-${VBOX_VERSION} && KERN_DIR=/linux-kernel/ make && cd ../../.. && \
cp amd64/src/vboxguest-${VBOX_VERSION}/*.ko $ROOTFS/lib/modules/$KERNEL_VERSION-tinycore64 && \
mkdir -p $ROOTFS/sbin && cp x86/lib/VBoxGuestAdditions/mount.vboxsf $ROOTFS/sbin/
RUN depmod -a -b $ROOTFS $KERNEL_VERSION-tinycore64
RUN /make_iso.sh
CMD ["cat", "boot2docker.iso"]
@johannespetzold
Copy link
Author

How to use:

  1. git clone https://gist.github.com/johannespetzold/05b2fc00793a6ec0b0d6
  2. cd 05b2fc00793a6ec0b0d6
  3. bash build-image.sh
  4. mv boot2docker.iso ~/.boot2docker
  5. bash add-share.sh

To verify:
docker run -v $HOME/workspace:/workspace ubuntu ls /workspace should list the contents of $HOME/workspace on the host.

Source: boot2docker/boot2docker#284

@LuisMuniz
Copy link

Hi Johannes

I have followed your howto, and was able to patch boot2docker. However, when I run your last command:

$touch $HOME/workspace/hello
$ls -l $HOME/workspace
total 0
-rw-r--r--  1 lmuniz  staff  0 Aug 23 14:02 hello
$docker run -v $HOME/workspace:/workspace ubuntu ls /workspace

I get nothing.

The volume does seem to come from somewhere persistent, though, because:

$docker run -t -i -v $HOME/workspace:/workspace ubuntu /bin/bash
root@75c92d2786d5:/#touch /workspace/world
root@75c92d2786d5:/#ls /workspace/
world
root@75c92d2786d5:/#exit
$ls -l $HOME/workspace
total 0
-rw-r--r--  1 lmuniz  staff  0 Aug 23 14:02 hello
$docker run -t -i -v $HOME/workspace:/workspace ubuntu /bin/bash
root@75c92d2786d5:/#ls /workspace/
world

So the created file world does exist somewhere on a persistent folder.
When I inspect the container:

$ docker inspect 3ec323fa3d58 | grep -C 10 workspace
        "Tty": true,
        "User": "",
        "Volumes": null,
        "WorkingDir": ""
    },
    "Created": "2014-08-23T12:18:46.97519695Z",
    "Driver": "aufs",
    "ExecDriver": "native-0.2",
    "HostConfig": {
        "Binds": [
            "/Users/lmuniz/workspace:/workspace"
        ],
        "CapAdd": null,
        "CapDrop": null,
        "ContainerIDFile": "",
        "Devices": null,
        "Dns": null,
        "DnsSearch": null,
        "Links": null,
        "LxcConf": [],
        "NetworkMode": "bridge",
--
--
    "State": {
        "ExitCode": 0,
        "FinishedAt": "0001-01-01T00:00:00Z",
        "Paused": false,
        "Pid": 868,
        "Restarting": false,
        "Running": true,
        "StartedAt": "2014-08-23T12:18:47.25630493Z"
    },
    "Volumes": {
        "/workspace": "/Users/lmuniz/workspace"
    },
    "VolumesRW": {
        "/workspace": true
    }
}

Finally, a sanity check to make sure that $HOME/workspace resolves to /Users/lmuniz/workspace:

$echo "$HOME/workspace"
/Users/lmuniz/workspace

Do you have an idea of what may be going on?

@johannespetzold
Copy link
Author

Hi Luis, sorry for late response, just noticed your comment. I think the problem was that add-share.sh included "/Users/pivotal/workspace" instead of $HOME/workspace, which was the same on my machine but not on yours. I fixed it, so hopefully this will work for you now.

@haren
Copy link

haren commented Sep 10, 2014

Hi @johannespetzold,

I tried to use your scripts but every single time I get this (the container builds correctly):
modprobe: module vboxsf not found in modules.dep
2014/09/10 14:15:17 exit status 1

Have you come across this?

@poy
Copy link

poy commented Oct 7, 2014

Hello @ johannespetzold

I tried to use your scripts but every single time I get this (the container builds correctly):
modprobe: module vboxsf not found in modules.dep
2014/09/10 14:15:17 exit status 1

Have you come across this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment