node-convict icon indicating copy to clipboard operation
node-convict copied to clipboard

how to change the environment variables in docker run command

Open Tiramisupxl opened this issue 3 years ago • 0 comments

I have add the config.js file

var convict = require('convict');

convict.addFormat(require('convict-format-with-validator').ipaddress);

// Define a schema
const config = convict({
  env: {
    doc: 'The application environment.',
    format: ['production', 'development', 'test'],
    default: 'development',
    env: 'NODE_ENV'
  },
  ip: {
    doc: 'The IP address to bind.',
    format: 'ipaddress',
    default: '127.0.0.1',
    env: 'IP_ADDRESS',
    arg: 'host'
  },
  port: {
    doc: 'The port to bind.',
    format: 'port',
    default: 1234,
    env: 'PORT',
    arg: 'port'
  },
  redis: {
    db: {
      doc: 'Redis DB',
      format: Number,
      default: 0,
      env: 'REDIS_DB',
    },
    host: {
      doc: 'Redis Host',
      format: String,
      default: 'localhost',
      env: 'REDIS_HOST',
    },
    password: {
      doc: 'Redis Password',
      format: String,
      default: '',
      env: 'REDIS_PASSWORD',
    },
    port: {
      doc: 'Redis Port',
      format: Number,
      default: 6379,
      env: 'REDIS_PORT',
    },
  },
})


// Perform validation
config.validate({allowed: 'strict'});

module.exports = config;

and the project will be run in docker

when I run

docker run -it -p 30112:30112 -e REDIS_PORT=30012 xx-nodejs

the project still run with the REDIS_PORT equals 6379

Is there some steps I miss?

Tiramisupxl avatar Jan 12 '22 08:01 Tiramisupxl