Short answer, Yes. 

During docker build, just execute it, the same way, you doing anything when configure IRIS

While docker container starts, you can execute script, which will be called after start of IRIS

Just add it in the Dockerfile, trainmodel.sh, should contain iris session script to start model train

CMD ["-a", "/trainmodel.sh"]

Is it possible to get also some stability in containers?

Here is the list of tags available on containers.intersystems.com

requesting list . done
repository: intersystems/irishealth-community
tags:
- 2020.1.1.408.0
- 2020.3.0.221.0
- 2020.4.0.547.0
- 2021.1.0.215.3
- 2022.1.0.152.0
- 2022.1.0.164.0
- 2022.1.0.172.0

Where is 2021.2?

And for the licensed version

repository: intersystems/irishealth
tags:
- 2019.1.1.615.1
- 2019.1.3.722.0
- 2020.1.0.217.1
- 2020.1.1.408.0
- 2020.1.2.517.0
- 2020.2.0.211.0
- 2020.3.0.221.0
- 2020.4.0.547.0
- 2021.1.0.215.0
- 2021.1.2.338.0
- 2021.2.0.651.0
- 2022.1.0.152.0
- 2022.1.0.164.0
- 2022.1.0.172.0

The only place where available 2021.2 CE version, is on Docker Hub, which now says it's deprecated, without any announcements. Just closed one of the ways used to download images.

127.0.0.1 will not work, due to it's still different host, and in case of this sam bundle, it should point to sam's iris. And will not work it, because, it should be available for prometheus container, not just for IRIS container for sam. So, you have to use, it's name as a host iris

And to access, some IRIS external to docker, you may use host.docker.internal hostname, or docker.for.mac.localhost with Docker on macOS

So, the first line is points to SAM's IRIS, and second to an IRIS outside

I think host.docker.internal was added in some recent versions of Docker, so, probably check the version of Docker