Down container A on container B start

Hi All!
I have an interesting task I can’t solve.
So, I want next steps to execute:
1 - build and start container “nginx” with config1
2 - build and start container “certbot” and use container "nginx"
and after “certbot” container finished it’s work
3 - stop container “nginx”, rebuild it with config2 and start it

Is it possible with docker-compose.yml?

Thank you!