Hi, I am trying to set Environment variables in docker container like below in docker composer file. Please let me know if it is not correct.
docker-compose.yml (424 Bytes)
Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!
Did you like my answer?
To set environment variables in a Docker container using a docker-compose.yml
file, you can use the environment
key within the service definition. Here is an example of how you can do this:
version: '3.8'
services:
my_service:
image: my_image:my_tag
environment:
- MY_ENV_VAR1=value1
- MY_ENV_VAR2=value2
In this example, my_service
is the name of the service, my_image:my_tag
is the Docker image and tag, and MY_ENV_VAR1
and MY_ENV_VAR2
are the environment variables being set with their respective values.
If you are using TorizonCore and want to use the predefined environment variables provided by Torizon, you can reference them directly in your docker-compose.yml
file. For example:
version: '3.8'
services:
weston:
image: torizon/weston:$CT_TAG_WESTON
environment:
- MY_ENV_VAR1=value1
- MY_ENV_VAR2=value2
In this example, $CT_TAG_WESTON
is an environment variable provided by TorizonCore that resolves to the appropriate tag for the Weston container.
Make sure to prepend the variable name with a dollar sign when running a command on Linux, as shown in the example.
If you encounter any issues or need further assistance, please provide more details about the specific problem you are facing.
Please, also check if these links can help you solve your problem:
Build/bundle in blowing away ENV variables in docker-compose.yml.
Greetings @khaled.hassan,
You can more or less follow what the ToradexAI has suggested. For more details, please see the following regarding setting environment variables in a container: Set environment variables | Docker Docs
Best Regards,
Jeremias