Build binaries only once, and run the same one on each of the environments. No matter if they are in a form of Docker images or JAR packages; building only once eliminates the risk of differences introduced by various environments. It also saves time and resources:
- Build once, and pass the same binary between environments.
- Use artifact repository to store and version binaries. Don't ever use the source code repository for that purpose.
- Externalize configurations and use a configuration management tool to introduce differences between environments.