I think, you are referring to different Build Strategy Options. And, in your question, you probably missed the Pipeline Build strategy.
Source to Image
Suppose, you have developed a basic NodeJS back-end application. Your aim is to quickly get it up and running in an OpenShift cluster. When I say quickly, I mean, not having to pick up Docker knowledge. In such a scenario, you would use S2I.
- Include a
start script in package.json to point to node index.js.
- Commit code to GitHub (or any other Git repository).
oc new-app .
- Done.
Docker
Continuing with the basic NodeJS backend example, you may realise that the base NodeJS image used by OpenShift may not be suitable for you (for any number of reasons). Maybe, you want to use Docker official NodeJS image. Of course, there maybe other non-NodeJS reasons to build a container for your application e.g. special environment variables, etc. Here, you would use a Dockerfile.
Docker image from Docker Hub
You could also deploy a pre-built Docker image. Note that, by default, OpenShift security constraint does not allow you to run containers as root. The article link calls this and a workaround for this constraint.
RedHat Registry
Same as in previous case, however, this deployment needs secrets as described in this article (requires login).
So, as long as, your container repository can be accessed in an OpenShift 'blessed' manner, you can definitely build image outside and have it pulled in for deployment.
Binary
The closest that I can quote as a 'scenario' is probably this question. Else, perhaps, the build approach is so niche that, it is better done in a 'controlled' environment before it is to be executed.
My preference
Speaking for myself, I would follow this path.
- The developers (including myself) needs to focus on getting the functionality done - so, use S2I.
- The operations team (including myself) needs to focus on packaging - so, use developed functionality in 1 and convert into a
Dockerfile. Or, even a Jenkinsfile.
- The management team (including myself) is sensitive towards putting images on the internet - so, push the Docker images to a private repository.
- If all of the above is to be done for something proprietary, use Binary build option.
Hope this helps.
s2iprogram outside of OpenShift as well to create an image that you then deploy to OpenShift. Not that it necessarily explains why one way would be used over another, but if you haven't already you might read openshift.com/deploying-to-openshift which covers each. - Graham Dumpleton