node.jsdockerdocker-swarm

Read value of docker config from nodejs app


I have created a docker config from a json file, I need my node.js app to read the value(json) from the configs, how can I achieve that?

docker config create my_config ./config.json

>dg426haahpi5ezmkkj5kyl3sn

docker config ls

>ID                          NAME                CREATED             UPDATED
 dg426haahpi5ezmkkj5kyl3sn   my_config           7 seconds ago       7 seconds ago

Solution

  • To access docker configs they are mounted into services. This can be done on the docker service create command line but usually via the configs compose directive.

    compose.yml

    configs:
      node_config:
        external: true
        name: my_config
    
    services:
      my_node_service:
        image: node:lts
        configs:
          - source: node_config
            target: /app/config.json