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,

  • TERM environment variable not set with Docker on Google Compute Engine
  • how to solve error in docker-compose?
  • TLS handshake error
  • Can I run/convert a Docker-Compose project with/to CoreOS rkt?
  • How to use kube-proxy to forward https serivce in k8s?
  • Using private docker registry for GitLab CI
  • 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?

  • Externalize to docker env
  • GitLab CI ERROR: Preparation failed: Post https…docker%3Adind: net/http: timeout awaiting response headers
  • Docker-Compose Up Works but Eb Local Run does not
  • Rebuild Docker container on file changes
  • How to debug Symfony command using Xdebug and phpStorm?
  • Can I get an image digest without downloading the image?
  • 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.