Keep files which are created during build

I want to deploy my Magento 2 application using docker to production using CodeBuild.

For this I do the following steps

  1. build an image and copy data into it
  2. when the image is build I exec into it, to put the application in production mode and to generate static files.

How can I keep those file which are generated in the docker container and preserve it into the image?

Thanks