简体   繁体   English

读取 docker-compose 或 docker 文件中的配置文件

[英]Read configuration file inside docker-compose or in docker file

Is it possible to read a configuration file eg json or yml file inside docker-compose and then parse the file and install the libraries listed in that file.是否可以在 docker-compose 中读取配置文件,例如 json 或 yml 文件,然后解析文件并安装该文件中列出的库。 For example例如

modules.json模块.json

{
  "base": {
  },
  "myproject": {
    "apcu": "php-apcu",
    "memcache": "php-memcache",
    "xmlrpc": "php-xmlrpc",
    "mysql": "php-mysql",
    "gd": "php-gd",
    "soap": "php-soap",
    "zip": "php-zip"
  }
}

And then have this referenced in the.env file like MODULE=myproject然后在 MODULE=myproject 之类的 .env 文件中引用它

Inside the DockerFile I would then like to do在 DockerFile 里面我想做

RUN apt-get -y --no-install-recommends install php-apcu

etc? ETC?

In Dockerfile you should:在 Dockerfile 中,您应该:

  1. install the jq package to manipulate with json.安装 jq package 以使用 json 进行操作。
  2. copy your.json file into container将 your.json 文件复制到容器中
  3. install needed dependencies安装所需的依赖项

Dockerfile example: Dockerfile 示例:

RUN apt-get install -y jq
COPY modules.json .
RUN cat modules.json | jq .myproject[] | sed -e 's/"//g' -e "s/'//g" | xargs apt-get -y --no-install-recommends install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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