简体   繁体   中英

Sharing a configuration file to multiple docker containers

Suppose I have the following configuration file on my Docker host, and I want multiple Docker containers to be able to access this file.

/opt/shared/config_file.yml

In a typical non-Docker environment I could use symbolic links, such that:

/opt/app1/config_file.yml -> /opt/shared/config_file.yml
/opt/app2/config_file.yml -> /opt/shared/config_file.yml

Now suppose app1 and app2 are dockerized. I want to be able to update config_file.yml in one place and have all consumers (docker containers) pick up this change without requiring the container to be rebuilt.

I understand that symlinks cannot be used to access files on the host machine that are outside of the docker container.

The first two options that come to mind are:

  1. Set up an NFS share from docker host to docker containers
  2. Put the config file in a shared Docker volume, and use docker-compose to connect app1 and app2 to the shared config docker

I am trying to identify other options and then ultimately decide upon the best course of action.

What about host mounted volumes? If each application is only reading the configuration and the requirement is that it lives in different locations within the container you could do something like:

docker run --name app1 --volume /opt/shared/config_file.yml:/opt/app1/config_file.yml:ro app1image
docker run --name app2 --volume /opt/shared/config_file.yml:/opt/app2/config_file.yml:ro app2image

The file on the host can be mounted at a separate location per container. In Docker 1.9 you can actually have arbitrary volumes from specific plugins to hold the data (such as Flocker ). However, both of these solutions are still per host and the data isn't available on multiple hosts at the same time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM