When you create a new container, you can specify one or more environment variables.
Environment variables are key/values pairs which are made available to all instances within the workload.
Environment variables are used to set configuration values that are defined at runtime or during deployment, but are not embedded within a container image.
For example, for an application that accesses a third-party API, credentials may be required to authenticate. For security reasons, credentials should not be stored within the image, but are available at runtime through environment variables. This practice allows for credentials to be rotated, as well as avoids leaked credentials from the image and restricts access.
Set environment variables
You can set environment variables when you first create a container.
In the StackPath Control Portal, you will see the following workload settings:
Use Environment Variables to configure an application’s operation.
|Secret Environment Variables||
Use Secret Environment Variables to protect sensitive application information.
|Downward API Environment Variables||
Use Downward API Environment Variables to expose application information to the workload and other instances in the same workload.
To create a container and set environment variables:
- In the StackPath Control Portal, in the left-side navigation menu, Edge Computer.
- Click Workloads.
- Click Create Workloads.
- Follow the on-screen instructions.
To learn more, see Create and Manage Virtual Machines, Containers, and Workloads.
Access environment variables
To access an environment variable programmatically, pull the variables from the OS or process.
To list these variables, in a terminal, ssh into your container.
- To list all variables in the current session, use the standard command printenv.
- To list all system wide variables use the standard command set.
The following example displays pulling the two system variables: