Copy or scp files to /var/lib/boot2docker for boot2docker VM managed by docker-machine

To use Docker on OS X, I’m using a boot2docker VM running in VirtualBox, managed by docker-machine. The boot2docker documents mention a persistence volume /var/lib/boot2docker. I would like to copy a file on the host filesystem over to the boot2docker VM.

I thought that docker-machine’s scp command would work for this,

  • Running Nightwatch test inside docker - Selenium server doesn't start
  • About workaround on bug of runc
  • Docker Container Failed to Run
  • JVM Memory Allocation In Docker (LXC) Container
  • Unable to push a plugin using docker plugin push command
  • Docker Akka-Http application endpoint not reachable
  • docker-machine scp dockerhost:/var/lib/boot2docker/

    Unfortunately, this gives

    scp: /var/lib/boot2docker/ Permission denied
    exit status 1

    Checking the file permissions, we can see that root is the only one with write permissions to this directory, by default:

    docker@dockerhost:~$ ll -d /var/lib/boot2docker
    lrwxrwxrwx    1 root     root            29 May 31 17:40 /var/lib/boot2docker -> /mnt/sda1/var/lib/boot2docker/
    docker@dockerhost:~$ ll -d /mnt/sda1/var/lib/boot2docker
    drwxr-xr-x    6 root     root          4096 May 31 17:40 /mnt/sda1/var/lib/boot2docker/

    It is not possible to specify the user root as the one to use with docker-machine scp.

    How does one copy files to /var/lib/boot2docker, preferably from the host machine?

  • Docker, and small production server infrastructure advices
  • Mysql socket is missing in my homestead docker container
  • Gradle task for Java playground
  • How to setup environments for MERN apps
  • Docker container behavior when used in production
  • Kubernetes cronjob reports “found invalid field” for failed and successfuJobsHistoryLimit
  • One Solution collect form web for “Copy or scp files to /var/lib/boot2docker for boot2docker VM managed by docker-machine”

    I could not find a way to do this using docker-machine scp. I did discover that, at least for OS X, the /Users directory of the host machine is mounted as a volume in the docker-machine VM, meaning that if the file is within the host file system under that directory, the VM can access it verbatim.

    Knowing this, my workaround was to use docker-machine ssh to issue a cp command for the files I needed transferred.

    docker-machine ssh dockerhost sudo cp /Users/username/path/to/ /var/lib/boot2docker/
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.