RogerRoger
RogerRoger

Reputation: 396

Docker data container, boot2docker, and the local file system

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

Answers (1)

K. Alan Bates
K. Alan Bates

Reputation: 3164

Docker Volumes User Guide


I will use two docker containers for my simple example

marginalized_liskov and plagiarized_engelbart

Mount a Host Directory as a Data Volume (at runtime)

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.


Create a Named Volume in a container and mount another container to that volume

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

Related Questions