How do I read a docker environment variable within a js script?

I have a react app hosted on a node docker container.
I run it and pass it an environment variable

 docker run -t -e "ADMIN_HOST_ENV=" -p 3000:3000 "myapp"

How can I get that “ADMIN_HOST_ENV” environment variable within the app?

  • Mule performance tuning with limited resources
  • How can I expose the dynamic $PORT from Heroku in a Dockerfile?
  • How to connect Docker Machine to a remote Docker VirtualBox
  • Why I receive permission denied in Docker deployment?
  • Docker: correct way of persisting container data to host
  • How to resize docker container's cpu-share value dynamiclly?
  • Docker volume which is read-only on the host
  • Is there a way to add the Docker host to a container's /etc/hosts using docker-compose?
  • Linked docker containers can't communicate with each other
  • Dynamically serving django docker containers
  • No space left for new subnet when Docker network get address from Flannel
  • How to create --link for 2 containers to link to each other?
  • One Solution collect form web for “How do I read a docker environment variable within a js script?”

    If this is just about the node backend, there’s already a question with a answer: Read environment variables in Node.js

    On the frontend, you’ll have several options to get at it, create an endpoint to get it, write it to a .js file that’s referenced by the frontend, pass it up as a cookie, keep it backend side and only reference it when you hit the backend, etc.

    I check environment variables when I run my server, write them to an environment.js, and then reference that environment.js in my index.html.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.