{"id":1647,"date":"2015-12-21T23:00:16","date_gmt":"2015-12-22T04:00:16","guid":{"rendered":"http:\/\/unitstep.net\/?p=1647"},"modified":"2015-12-22T22:01:11","modified_gmt":"2015-12-23T03:01:11","slug":"accessing-the-host-filesystem-from-a-docker-container-on-os-x-or-windows","status":"publish","type":"post","link":"https:\/\/unitstep.net\/blog\/2015\/12\/21\/accessing-the-host-filesystem-from-a-docker-container-on-os-x-or-windows\/","title":{"rendered":"Accessing the host file system from a Docker container on OS X or Windows"},"content":{"rendered":"

Mounting (or sharing) a directory from the Docker daemon host into a container is simple enough. Example:<\/p>\n

$ docker run -v [host directory path]:[container directory path] -it [image name]<\/code><\/pre>\n

However, on OS X and Windows, the Docker daemon (currently) runs inside of a Linux VM, that by default is run using VirtualBox. (Since Docker only runs natively on Linux) So, you’d be mounting a folder from the Linux VM<\/em>, which is probably not what you want if you want to share files from your host machine into the container.<\/p>\n

<\/p>\n

Thankfully, VirtualBox allows sharing of folders from your host machine into the VM where the Docker daemon resides. The Docker Linux VM is also auto-configured to mount either \/Users<\/code> (OS X) or C:\\Users<\/code> (Windows) into \/Users<\/code> on the Linux VM:<\/p>\n

\n\"\"\n<\/p>\n

This means we can mount \/Users<\/code> from the Linux VM into a container, allowing it access to your underlying host\/physical system’s files in \/Users<\/code> (OS X) or C:\\Users<\/code> (Windows).<\/p>\n

Here’s an example I used when playing around with the TensorFlow Docker image<\/a>:<\/p>\n

$ docker run -v \/Users:\/host\/Users -it b.gcr.io\/tensorflow\/tensorflow<\/code><\/pre>\n

This mounted \/Users<\/code> (from the local host file system) into \/host\/Users<\/code>, so I had access to source code files I was editing. (You could also make the container mount the file system as read-only by appending :ro<\/code> to the -v<\/code> argument.)<\/p>\n

To share other directories on your host system, you’d just need to add those to the Shared Folders for the VirtualBox Linux VM, then use another -v<\/code> argument to the docker<\/code> command to mount them into the container.<\/p>\n

Note that with this method you’re going through two levels of mounting\/sharing: From the ultimate host system to the Linux VM (via VirtualBox’s shared folders) and then from the Linux VM to the container. The first is likely to have a performance impact, so I wouldn’t use it in production. Then again, for production you should probably be using the native Linux version of Docker.<\/p>\n

References<\/h3>\n
    \n
  1. Manage data in containers: Docker Fundamentals<\/a><\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"

    Mounting (or sharing) a directory from the Docker daemon host into a container is simple enough. Example: $ docker run -v [host directory path]:[container directory path] -it [image name] However, on OS X and Windows, the Docker daemon (currently) runs inside of a Linux VM, that by default is run using VirtualBox. (Since Docker only […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[277],"tags":[],"_links":{"self":[{"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/posts\/1647"}],"collection":[{"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/comments?post=1647"}],"version-history":[{"count":16,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/posts\/1647\/revisions"}],"predecessor-version":[{"id":1678,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/posts\/1647\/revisions\/1678"}],"wp:attachment":[{"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/media?parent=1647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/categories?post=1647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/tags?post=1647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}