Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use NULL in environment variables supplied to docker run?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading