I am supplying environment variables in docker run as docker run --env-file <env_file_path>..... The Dockerfile executes a ruby script which reads the env variables.
# environment variable file
TEST_1=NULL
TEST_2=
TEST_3=""
# ruby script
print ENV['TEST_1'] # "NULL"
print ENV['TEST_2'] # ""
print ENV['TEST_3'] # "\"\""
How can I receive a nil values in ruby from the environment variables? What should the supplied environment variable value be?
>Solution :
How can I receive a nil values in ruby from the environment variables? What should the supplied value be?
You can’t, not directly. Unlike a language like ruby, environment variables do not have a concept of null values.
You’ll have to check for and convert a chosen value like an empty string, NULL or nil to an actual nil in your code.
You could use the mere presence / absence of the env variable, but the issue with that is that you can’t unset an environment variable once it’s set with docker, only set it to empty string.