I am trying to pass NODE_ENV=profiling-local from package.jso to Docker-compose and then run the script but it is not taking it and process.env.NODE_ENV= undefined is coming.
my docker-compose file:
version: "2"
services:
logs_db:
image: postgres
ports:
- "5434:5432"
expose:
- "5434"
volumes:
- data:/var/lib/postgresql/data
- ./db/setup.sql:/docker-entrypoint-initdb.d/seed.sql
networks:
- liven
environment:
POSTGRES_HOST_AUTH_METHOD: trust,
NODE_ENV: ${NODE_ENV}
event_engine:
build:
context: .
dockerfile: Dockerfile
entrypoint:
- 'sh'
- '-c'
- 'yarn install && yarn watch'
volumes:
- .:/src/app/
- /src/app/node_modules/
links:
- logs_db
depends_on:
- logs_db
networks:
- liven
volumes:
data:
driver: local
node_modules_volume:
my package.json
{
"name": "event-engine",
"version": "1.0.0",
"description": "event engine",
"main": "src/index.js",
"author": "DT Starts",
"license": "MIT",
"private": true,
"scripts": {
"watch": "nodemon -L --exec babel-node src/index.js --config nodemon.json",
"start": "node ./dist/index.js",
"build": "babel src -d dist",
"dev": "docker-compose up",
"profiling":"NODE_ENV=profiling-local docker-compose up"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/node": "^7.12.1",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/register": "^7.12.1",
"babel-eslint": "^10.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.20.1",
"nodemon": "^2.0.2",
"pino":"^6.11.2",
"dotenv": "^8.2.0"
},
"dependencies": {
"pg": "^7.18.2",
"redux": "^4.0.5",
"socketcluster-client": "^16.0.1",
"uuid": "^8.3.1"
}
}
after but in my index.js file process.env.NOD_ENV is coming undefined. I have tried almost every way to pass the enviromnet variable to docker-compose file from scrip of pacakge.json and from where my node.js code can take it but it is coming undefined.
You didn't specify how you run this compose file, but I guess you didn't pass the build-arg:
docker-compose up --build-arg NODE_ENV=<value>
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.