Using env variables from aws ssm and injecting into a docker build

I currently do my laravel migrations inside my Dockerfile.
When my dockerfile is built with Jenkins then the migrations execute. Im not sure if this is the best way but this is how it has been running.

The issue with this is that i have a .env.uat file with sensitive data inside like passwords for the aws rds database.

I want to clear these env variables from the .env.uat and rather inject them in somehow while doing a docker build.

I have tried everything from setting these in the environment object to setting build-args to even using and setting the ENV variables there

Whatever i do i cannot get these env values into my docker at build time so my migrations can run on UAT.

Any help or advice appreciated.