Build Docker image:
docker build -t read-env .
Run it with the env var set:
docker run --rm -d -e "foo-bar=ok" --name readenv read-env
Check logs:
$ docker logs readenv
list all env vars: {
NODE_VERSION: '20.5.1',
HOSTNAME: '44058092d956',
YARN_VERSION: '1.22.19',
HOME: '/root',
PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
PWD: '/'
}
read env var: foo-bar
undefined
Attach running NodeJS and check env vars:
$ docker exec -it readenv node
Welcome to Node.js v20.5.1.
Type ".help" for more information.
> process.env['foo-bar']
'ok'