Can I have packer "keep" an EC2 instance around until Im done using it to build images?

FYI I created a previous post asking about windows support: Can I use packer to build my big windows container images or not?

I have big windows containers I need to build

I want to have packer create an EC2 instance (the official windows ECS ami which has docker installed) and build a windows docker image and then push to ECR

BUT Im wondering if there is a way to “keep” that EC2 instance around until Im done?

So Im thinking the workflow would be like this:

  • Modify the dockerfile
  • Run packer build
  • Packer provisions a new EC2 instance, builds the image, pushes to EC2, but doesn’t delete the instance
  • Modify dockerfile more
  • Run packer build again
  • Packer uses the same instance to build and push
  • When Im done working on the dockerfile I run a command like “packer destroy” or something? And then packer deletes the EC2 instance

Is a workflow like this possible? I ask because it would be faster if I didn’t need to have packer create a new instance each time it builds

Thanks!

you can use the breakpoint provisioner to “pause” execution partway through a build until you’re done with an instance, which will allow you to keep it as long as you need. But you can’t rerun the build once paused, and you can’t repeat a build against the same instance.

I’m confused about whether the end product is the ec2 instance or the docker container. If the latter, why not launch the ec2 instance manually (without packer) and use packer from inside that instance to build your docker container?