如何将dockerfile环境变量传递给node.js文件?我按照docker文档传递ENV变量,没有传递任何变量。对此问题的任何见解?
dockerfile:
FROM 10.118.224.132:5000/node:8.6.0-wheezy
ENV PORT 6000
ENV iamIP2="10.118.225.199"
ENV iamPort 9999
ENV iamPort2=9997
RUN apt-get update
WORKDIR /usr/src/app
COPY package.json /usr/src/app
COPY . .
ENV mongoDBurl=10.118.225.149:27017/globalIndex
CMD ["node", "server.js"]
server.js:
"use strict";
const fs = require('fs');
const http = require('http');
const cors = require('cors');
const request = require('request');
const link1 = process.env.PROXY_IAM_URI;
const iamIP ="10.118.225.164"; console.log("iamIP: " + iamIP);
//const iamIP = /\d+.\d+.\d+.\d+/g.exec(link1)[0]; console.log("iamIP: "+iamIP);
//const iamPort = /\d{2,}$/g.exec(link1)[0]; console.log("iamPort "+ iamPort);
const iamPort =0; console.log("iamPort "+ iamPort);
var iamIP2 ; console.log("iamIP2 "+ iamIP2);
var iamPort2 ; console.log("iamPort2 "+ iamPort2);
console.log(响应):
[stdout][20d97485] iamIP: 10.118.224.164
[stdout][20d97485] iamPort 0
[stdout][20d97485] iamIP2 undefined
[stdout][20d97485] iamPort2 undefined
答案 0 :(得分:1)
您应该可以使用process.env
process.env.iamIP2 // "10.118.225.199"
process.env.iamPort // 9999
process.env.iamPort2 // 9997
process.env.mongoDBurl // 10.118.225.149:27017/globalIndex