Home > Software engineering >  How To Pass MySQL Credentials To Node Red Running In Docker
How To Pass MySQL Credentials To Node Red Running In Docker

Time:11-26

I have a DockerFile..

FROM nodered/node-red
COPY package.json .
COPY --from=golang  /go/src/app  /usr/app/
USER root
RUN npm install --unsafe-perm --no-update-notifier --no-fund --only=production
RUN npm install node-red-contrib-speedtest
RUN npm install node-red-node-mysql

ADD settings.js /data/settings.js
ADD flows_cred.json /data/flows_cred.json
ADD flows.json /data/flows.json

that is working ok and creates a couple of flows. The MySQL node is partly built, but the username and password are missing.

The docker image is invoked via docker-compose

Is there a way to pass the credenials at the dockerfile or docker-compose stage?

Looking at the flows.json file I can see definition..

{
    "id": "25d5a4648b3a030b",
    "type": "MySQLdatabase",
    "name": "XXXXXXXX",
    "host": "Database",
    "port": "3306",
    "db": "yyyyyy",
    "tz": "",
    "charset": "UTF8"
},

and hoped that I could just add a "user" and "password" to this section, but that doesn't seem to work.

CodePudding user response:

You can have Node-RED red environment variables as configuration options.

https://nodered.org/docs/user-guide/environment-variables

So if you open the flow in Node-RED and open the mysql configuration dialog you can replace the username/password fields with ${USERNAME} and ${PASSWORD} then pass the values in as environment variables to the container when it's started.

https://docs.docker.com/compose/environment-variables/#pass-environment-variables-to-containers

  • Related