将配置文件共享到多个Docker容器 [英] Sharing a configuration file to multiple docker containers

查看:230
本文介绍了将配置文件共享到多个Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的Docker主机上有以下配置文件,并且我希望多个Docker容器能够访问此文件。

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

在典型的非Docker环境中,我可以使用符号链接,例如:

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

现在假设docker和app1已被docker化。我希望能够在一处更新config_file.yml并让所有使用者(docker容器)都接受此更改,而无需重建容器。

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.

我了解符号链接不能用于访问Docker容器外部的主机上的文件。

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

想到的前两个选项是:


  1. 设置一个NFS从Docker主机到Docker容器的共享

  2. 将配置文件放入共享的Docker卷中,并使用docker-compose将app1和app2连接到共享的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

主机上的文件可以挂载在每个容器的单独位置。在Docker 1.9中,实际上您可以从特定插件中获取任意卷来保存数据(例如羊群)。但是,这两种解决方案仍是针对每个主机的,并且无法同时在多个主机上获得数据。

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.

这篇关于将配置文件共享到多个Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆