Reputation: 396
I'm slowly working my way through understanding current Docker practices. I'm on a Mac, and I'm using boot2docker.
I've been able to use the docker -v local/directory:container/directory method to link a container directory to my local file system. Great, now I can easily edit things like site code in my local Mac file system and have the changes immediately available to my container (e.g. /var/www/html).
I'm now trying to separate my containers into discrete concerns. For example, a Web, Database, and File (e.g. busybox) container would be useful for a Wordpress site. Thing is, I don't know how to make my file container define volumes that I can then link to my local OS (similar to the -v local/directory:container/directory used by boot2docker).
This is probably not the most eloquent question, as I'm still fumbling through learning Docker, but if you can understand what I'm trying to achieve, I'd really appreciate any guidance provided.
Thanks!
Upvotes: 1
Views: 860
Reputation: 3164
I will use two docker containers for my simple example
marginalized_liskov
and plagiarized_engelbart
docker run -d -P --name marginalized_liskov -v /host/directory/context:/container/directory/context poop python server.py
marginalized_liskov
is the name of the container.
poop
is not only my favorite palindrome, but also the name of the volume that we're creating.
"/host/directory/context"
is the location on the host that you want to mount
"/container/directory/context"
is the location you want your new volume to be created in your container
python
is of course the application to run
server.py
is the argument provided to "python" for this sample.
docker create -v /poop --name marginalized_liskov training/postgres
docker run -d --volumes-from marginalized_liskov --name plagiarized_engelbart ubuntu
This creates two containers.
marginalized_liskov
gets a volume created named poop
I built it from the postgres training image because that's what was used in the User Guide. Since we're just setting up a container to contain a data volume and not host applications, using the training/postgres image provides our functionality while remaining lean.
plagiarized_engelbart
mounts the volumes from marginalized_liskov
with the --volumes-from
flag.
Upvotes: 3