Use case: consistent package versioning (Linux)

Hello! I am new to docker and I was wondering if there is some proper or preferred way of handling consistent package versions.

TLDR:
I would like to build an image with docker that installs some software from some repository. After the first build I would like all subsequent builds to install the same version of the software from the repository as the first time.

Long version:
Another way to put it is that I want a very consistent environment. After my initial build, all subsequent builds should be EXACTLY the same. (Let’s say the cache is emptied)

My dream would be that during the first build all package versions are collected and stored. And then during the next build they are available be used again. This instead of the build script fetching the latest version of each software.

Thank you all!

/T