How can I get environment variables of docker in node js?

I am using docker to run node server.js
In terminal, I execute docker run --env-file .env -p 8080:8080 -d node-web-app and I am trying to use process.env in server.js to get environment variables in docker
However, RangeError: Invalid status code: 0 occurs.
How can I fix it and get the environment variables in docker?
Thanks in advance.

  • Running ejabberd inside docker container is causing PREVIOUS.LOG enoent crash
  • Is it possible for image to have multiple tags?
  • “Error Checking TLS connection: Host is not running” from docker-machine when SSHing into Windows host
  • What is the optimal way to run a Node API in Docker on Amazon ECS?
  • GC overhead limit exceeded in Docker when trying to build project by sbt
  • Deploy Django app with Docker
  • Deploying Docker containers with port-mapping on Mesos/Marathon
  • How to set environment variables via env-file
  • Docker-compose run service if another service status is 0 (success)
  • Importance of the place of CMD in Dockerfile
  • Running multiple docker instances in EC2
  • Winston Not Logging
  • One Solution collect form web for “How can I get environment variables of docker in node js?”

    That error is related to your HTTP handler, not env variables. Make sure you send a valid response.

     res.send('OK')
     res.send(JSON.stringify(process.env));
    
    
    docker run -e "test=1" -e "testb=2"
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.