How to do host-specific customization on docker images
Let me explain what I want with a silly example:
After I do “docker pull” to download an image to my host, I want to create a file /etc/myname on this image to have the exact name of this host. As a result, all containers running this image on this host can find the hostname by reading /etc/myname.
Plus, I want the file /etc/myname to be shared across all contains on this host. I know I can easily create this file separately in each container, but that’s not what I want.
(Again, this is just a silly example. I don’t actually need to store the hostname. I want to store a large amount of host-specific data in a shared file, without using a shared volume).
I can do that by manually creating the file myself, where $dir is the top-most layer of the image:
dir=17024e41f8b6c958c5c9e60bffa8b6c8b2da5a1235b6e18085d5059f9602f605 echo $HOSTNAME > /var/lib/docker/aufs/diff/$dir/etc/myname
But is there a less hacky way to do this?
One Solution collect form web for “How to do host-specific customization on docker images”
The easiest way to do this would be to use a shared volume, and that is in fact the only way to do it currently. I assume you know about bind mounting in docker, but I’ll show here just in case.
docker run command, as well as passing
-v <volume name>:<path in container> you can also pass
<path on host>:<path in container>. So you could have your metadata in the same place on each host and then bind mount it into the containers.