简体   繁体   中英

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. For example

modules.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

Inside the DockerFile I would then like to do

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

etc?

In Dockerfile you should:

  1. install the jq package to manipulate with json.
  2. copy your.json file into container
  3. install needed dependencies

Dockerfile example:

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

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