Skip to content

Instantly share code, notes, and snippets.

@mattes
Last active June 6, 2025 20:56
Show Gist options
  • Save mattes/2d0ffd027cb16571895c to your computer and use it in GitHub Desktop.
Save mattes/2d0ffd027cb16571895c to your computer and use it in GitHub Desktop.

Revisions

  1. mattes revised this gist Jun 11, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Build boot2docker.iso with VirtualBox Guest Additions

    __Allows me to mount /Users into boot2docker__ which is incredibly useful for
    my local Docker environment under Mac OSX. So from Mac I can do sth like this:
    my local Docker environment under Mac OSX. So from Mac I can do sth like this:
    ``docker run -v /Users/mattes/somedir:/data/somedir [..]``.


  2. mattes revised this gist Jun 11, 2014. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,17 @@
    # Build boot2docker.iso with VirtualBox Guest Additions

    __Allows me to mount /Users into boot2docker__ which is incredibly useful for
    my local Docker environment under Mac OSX.
    my local Docker environment under Mac OSX. So from Mac I can do sth like this:
    ``docker run -v /Users/mattes/somedir:/data/somedir [..]``.


    This Dockerfile will download the latest boot2docker image (see ``FROM boot2docker/boot2docker``)
    and adds VirtualBox Guest Additions for your running VirtualBox version.

    See also https://github.com/boot2docker/boot2docker/pull/284.

    I tried to make the mount permanent from within the VirtualBox GUI (see screenshot)
    but that didn't work. So I added the mount to ``/var/lib/boot2docker/bootsync.sh`` (see Dockerfile.tmpl)
    I tried to make the mount permanent from within the VirtualBox GUI (see __screenshot__)
    but that __didn't work__. So I added the mount logic to ``$ROOTFS/etc/rc.d/vbox-guest-additions-permanent-mount`` (see Dockerfile.tmpl)

    See build log here https://gist.github.com/mattes/6bed15318e93925b1280

  3. mattes revised this gist Jun 11, 2014. 3 changed files with 32 additions and 4 deletions.
    10 changes: 8 additions & 2 deletions Dockerfile.tmpl
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # $VBOX_VERSION should probably be something like 4.3.10 or somesuch
    #
    # using VirtualBox version $VBOX_VERSION

    FROM boot2docker/boot2docker
    RUN apt-get install p7zip-full

    @@ -18,6 +18,12 @@ RUN echo "" >> $ROOTFS/etc/motd; \
    echo " boot2docker with VirtualBox guest additions version $VBOX_VERSION" >> $ROOTFS/etc/motd; \
    echo "" >> $ROOTFS/etc/motd

    # make mount permanent @todo it works, but its ugly. where should this go?
    RUN echo '#!/bin/sh' >> $ROOTFS/etc/rc.d/vbox-guest-additions-permanent-mount; \
    echo 'sudo modprobe vboxsf && sudo mkdir /Users && sudo mount -t vboxsf home /Users' >> $ROOTFS/etc/rc.d/vbox-guest-additions-permanent-mount
    RUN chmod +x $ROOTFS/etc/rc.d/vbox-guest-additions-permanent-mount
    RUN echo '/etc/rc.d/vbox-guest-additions-permanent-mount' >> $ROOTFS/opt/bootsync.sh

    RUN depmod -a -b $ROOTFS $KERNEL_VERSION-tinycore64
    RUN /make_iso.sh
    CMD ["cat", "boot2docker.iso"]
    26 changes: 24 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,42 @@
    # Build
    # Build boot2docker.iso with VirtualBox Guest Additions

    This will download the latest boot2docker image (see ``FROM boot2docker/boot2docker``)
    __Allows me to mount /Users into boot2docker__ which is incredibly useful for
    my local Docker environment under Mac OSX.


    This Dockerfile will download the latest boot2docker image (see ``FROM boot2docker/boot2docker``)
    and adds VirtualBox Guest Additions for your running VirtualBox version.

    See also https://github.com/boot2docker/boot2docker/pull/284.

    I tried to make the mount permanent from within the VirtualBox GUI (see screenshot)
    but that didn't work. So I added the mount to ``/var/lib/boot2docker/bootsync.sh`` (see Dockerfile.tmpl)

    See build log here https://gist.github.com/mattes/6bed15318e93925b1280


    ```bash
    # generate Dockerfile from Dockerfile.tmpl
    chmod +x build_docker.sh
    ./build_docker.sh

    # build the actual boot2docker.iso with virtual box guest additions
    docker build -t mattes/boot2docker-vbga .

    # the following line is proposed in many tutorials, but does not work for me
    # (it outputs an iso that won't work)
    docker run -i -t --rm mattes/boot2docker-vbga > boot2docker.iso

    # so I do:
    docker run -i -t --rm mattes/boot2docker-vbga /bin/bash
    # then in a second shell:
    docker cp <Container-ID>:boot2docker.iso boot2docker.iso

    # use the new boot2docker.iso
    boot2docker stop
    mv ~/.boot2docker/boot2docker.iso ~/.boot2docker/boot2docker.iso.backup
    mv boot2docker.iso ~/.boot2docker/boot2docker.iso
    VBoxManage sharedfolder add boot2docker-vm -name home -hostpath /Users
    boot2docker up
    boot2docker ssh "ls /Users" # to verify if it worked
    ```
    Binary file added virtualbox-boot2docker-guest-addtions.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  4. mattes revised this gist Jun 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,4 @@ boot2docker stop
    mv ~/.boot2docker/boot2docker.iso ~/.boot2docker/boot2docker.iso.backup
    mv boot2docker.iso ~/.boot2docker/boot2docker.iso
    boot2docker up
    ```
    ```
  5. mattes revised this gist Jun 10, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,10 @@ chmod +x build_docker.sh

    docker build -t mattes/boot2docker-vbga .
    docker run -i -t --rm mattes/boot2docker-vbga > boot2docker.iso

    # use the new boot2docker.iso
    boot2docker stop
    mv ~/.boot2docker/boot2docker.iso ~/.boot2docker/boot2docker.iso.backup
    mv boot2docker.iso ~/.boot2docker/boot2docker.iso
    boot2docker up
    ```
  6. mattes revised this gist Jun 10, 2014. 2 changed files with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # Build

    This will download the latest boot2docker image (see ``FROM boot2docker/boot2docker``)
    and adds VirtualBox Guest Additions for your running VirtualBox version.

    See also https://github.com/boot2docker/boot2docker/pull/284.

    ```bash
    chmod +x build_docker.sh
    ./build_docker.sh

    docker build -t mattes/boot2docker-vbga .
    docker run -i -t --rm mattes/boot2docker-vbga > boot2docker.iso
    ```
    Empty file modified build_docker.sh
    100644 → 100755
    Empty file.
  7. mattes revised this gist Jun 6, 2014. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions build_docker.sh
    Original file line number Diff line number Diff line change
    @@ -22,5 +22,3 @@ write_vbox_dockerfile(){
    }

    write_vbox_dockerfile
    docker build -t="my-boot2docker" .
    docker run -i -t --rm my-boot2docker > boot2docker.iso
  8. @tgross tgross revised this gist May 20, 2014. 2 changed files with 10 additions and 2 deletions.
    8 changes: 7 additions & 1 deletion Dockerfile.tmpl
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # $VBOX_VERSION should probably be something like 4.3.10 or somesuch
    #
    FROM boot2docker/boot2docker-rootfs
    FROM boot2docker/boot2docker
    RUN apt-get install p7zip-full

    RUN mkdir -p /vboxguest && \
    @@ -14,4 +14,10 @@ RUN mkdir -p /vboxguest && \
    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 echo "" >> $ROOTFS/etc/motd; \
    echo " boot2docker with VirtualBox guest additions version $VBOX_VERSION" >> $ROOTFS/etc/motd; \
    echo "" >> $ROOTFS/etc/motd

    RUN depmod -a -b $ROOTFS $KERNEL_VERSION-tinycore64
    RUN /make_iso.sh
    CMD ["cat", "boot2docker.iso"]
    4 changes: 3 additions & 1 deletion build_docker.sh
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,6 @@ write_vbox_dockerfile(){
    fi
    }

    write_vbox_dockerfile
    write_vbox_dockerfile
    docker build -t="my-boot2docker" .
    docker run -i -t --rm my-boot2docker > boot2docker.iso
  9. @nsfmc nsfmc created this gist Mar 29, 2014.
    17 changes: 17 additions & 0 deletions Dockerfile.tmpl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # $VBOX_VERSION should probably be something like 4.3.10 or somesuch
    #
    FROM boot2docker/boot2docker-rootfs
    RUN apt-get install p7zip-full

    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
    24 changes: 24 additions & 0 deletions build_docker.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/usr/bin/env sh

    get_vbox_version(){
    local VER
    VER=$(VBoxManage -v | awk -F "r" '{print $1}')
    if [ -z "$VER" ]; then
    echo "ERROR"
    else
    echo "$VER"
    fi

    }

    write_vbox_dockerfile(){
    local VER
    VER=$(get_vbox_version)
    if [ ! "$LATEST_RELEASE" = "ERROR" ]; then
    sed "s/\$VBOX_VERSION/$VER/g" Dockerfile.tmpl > Dockerfile
    else
    echo "WUH WOH"
    fi
    }

    write_vbox_dockerfile