How to store environment variable in dockerfile or docker compose.yaml whose value is fetched from the os on which it gets deployed?

I want to use some env variables in my app, that runs on docker container. How can I get those environment variables in my code?

If I use dockerfile or docker-compose yaml, then how can I export it to read the values from the os on which it runs eventually and how can it be read in the code?

So for example, if I run my docker on AWS instances, I need the AWS keys from the instance to be used in my containerized app.

Source: Docker Questions