Skip to content

how to change the environment variables in docker run command #401

@Tiramisupxl

Description

@Tiramisupxl

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions