如何访问nodeJS应用程序中的docker ENVvariables

我正在使用这个Dockerfile:

FROM node:8.4.0 COPY . / ENV MONGO_URL=mongodb://mongo-container/data ENV PORT=80 EXPOSE 80 CMD node /index.js 

在index.js文件中,我想检查ENVvariables。 由于Docker镜像在生产环境中使用,如果ENVvariables未设置,我将使用开发环境运行该应用程序。 类似的东西:

index.js

 const mongoUrl = ENV.MONGO_URL || 'mongodb://localhost:3001' 

运行Docker镜像应该使用高效的mongoDB,在本地运行应该使用localhost DB

process.env对象包含所有的用户环境variables。 查看链接了解更多信息https://nodejs.org/api/process.html#process_process_env