When a new StackPath Edge Computing container is created, one or many environment variables can be specified. These are key/value pairs which are made available to all instances running in the Workload.
Environment variables are used to set configuration values that are defined at runtime or deploy, rather than embedded within a container image.
For example, you might have an application which accesses a 3rd party API that requires credentials to authenticate. Good security practice is that credentials are not stored within the image, but provided at runtime through environment variables. This allows for easy credential rotation, avoids leaking credentials as part of the image and restricts access only to those who might need them.
Setting Environment Variables
Environment variable key/value pairs can be set when creating the workload. For example, in the StackPath Control Portal UI:
Accessing Environment Variables
When you set a variable during workload creation, each becomes available within all instances running in the workload. You can access these environment variables programmatically in most languages by pulling the variables from the os or process a given program is running in.
To list these variables in terminal ssh into your container.
- You can list all variables in the current session using the standard command printenv.
- To list all system wide variables use the standard command set.
Below is an example of pulling the two system variables set previously in this article.
If you have any additional question or concerns please feel free to reach out to our 24x7 Support team via chat and we will be happy to help.