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,

  • Dockerized Neo4j ignoring previous database
  • error parsing HTTP 404 response body: invalid character '<' looking for beginning of value docker
  • What alternatives are there for Docker on Solaris 11.3?
  • How do I Docker COPY as non root?
  • Docker Container Best Practices
  • Docker is not adding a network shared folder as a data volume
  • 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?

  • In the perspective of runtime performance, is Docker running on cloud services efficient?
  • Docker-machine - IP address conflict
  • Deploying WAR file in Docker container
  • Why am I getting a *much* worse performance with Docker Stack than Docker Compose?
  • Is there a way to create a copy of the docker image on the same host?
  • Docker run vs create
  • 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.