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.

  • curl from docker ubuntu image
  • Docker orchestration
  • Rancher can pull images from private registry
  • Docker : Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  • Passing arguments to another process as they were entered on the command line with a bash script
  • Channgel Creation Failed. GRPC timeout
  • 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:

    echo $HOSTNAME > /var/lib/docker/aufs/diff/$dir/etc/myname

    But is there a less hacky way to do this?

  • passing file to docker command
  • npm update failed in docker
  • Singularity + Kubernetes
  • How would I have AWS EC2 Container Service grab a docker image from a private repo on Docker Hub using Cloud Formation?
  • Convert HTML to PDF using wkhtmltopdf, docker in ASP.NET Core
  • vagrant up --provider=docker SSL cert issue
  • 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.

    To the 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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.