You'll want to use BuildKit (`docker buildx`), see https://docs.docker.com/develop/develop-images/build_enhance...
[edit] My bad, that works for secrets needed at build time, not at runtime of course.