How to share files between OSX and container?

I’m finding the documentation very sparse on how to do this. I’m running Docker version 1.12.0-a(build: 11213).

I want to be able to copy files from my host machine to my centos container.

The normal Docker mechanisms work(*)(**): you can build an image that COPY content from the build directory into the image, or docker cp files into a running container, or use docker run -v to inject a host directory. IMHO it’s better practice to build an image out of your application and docker build is both efficient and robust.

(*) …except, by default, you can’t quite inject arbitrary directories with docker run -v, though anything in /Users is allowed; you can change it via the whale menu
(**) …though for large content, docker run -v is reportedly quite slow and may have stability issues; look for long “Docker for Mac” threads on the forum

David,

That is very helpful thank you.

I’m under impression that you can map directories as well though and it
would sync them ?

So maybe to expand on this question, if I knew how to map a directory then
I could both copy files, I could point edit code files etc as well ?

Thanks !
Steve

Mounting volumes (the -v option) does exactly that. You can mount a host directory onto the container so it is visible to the container. Sync is bi-directional. Changes done in the container on the mounted directory reflects on your host, and vice versa.

For example, developing PHP on Apache. You can run an Apache container, mounting your project on your host to /var/www/html. The Apache container sees your files and serves it. At the same time, you can also edit the files on the host. You upload a file to your PHP site, it gets saved to the mounted directory, you will see that file on the host.