๐ฏ What is S2I?
S2I = Source-to-Image
โ Itโs a build process invented by OpenShift (Red Hat) to automate:
“Take my source code + take a base image โ and build a new runnable application container.”
You give it:
- Source code (like HTML, PHP, Python app, Java code)
- S2I base image (like nginx, nodejs, python builder image)
It gives you:
- New container image that has both the code + runtime server inside.
๐ฆ What is an S2I Base Image?
An S2I base image is a special Docker container image that:
| Feature | Description |
|---|---|
| Has a web server, app server, or runtime pre-installed | e.g., nginx, nodejs, python |
Has scripts inside (assemble, run) | Helps OpenShift build a new app image automatically |
| Waits for your source code | Your app code is injected during build |
| Produces a new runnable image | Combining base + your code |
โ S2I base images are made specially for OpenShift pipelines.
They are not meant to be directly run without building first.
๐ง Easy Example:
Imagine you want to deploy a static website:
| Traditional Way | S2I Way |
|---|---|
| You manually build Docker image (nginx + your site files) | You push your HTML files to GitHub |
| You write Dockerfile yourself | OpenShift runs oc new-app nginx-s2i~your-git-repo |
| You manually build/push container | OpenShift builds everything automatically |
โ Less work for you โ More automation for you
๐ข Example of S2I base images:
| Base Image | Language/Runtime | Usage |
|---|---|---|
registry.redhat.io/rhscl/nginx-116-rhel7 | nginx | Serve HTML sites |
registry.redhat.io/rhscl/nodejs-14-rhel7 | Node.js 14 | Node.js apps |
registry.redhat.io/rhscl/python-38-rhel7 | Python 3.8 | Python apps |
registry.redhat.io/rhscl/php-73-rhel7 | PHP 7.3 | PHP apps |
All these are S2I base images.
๐ How an S2I base image actually works inside:
It includes scripts like:
| Script | Purpose |
|---|---|
assemble | How to copy your source code into the container and prepare the app |
run | How to start the server when container runs |
save-artifacts | Optional, to cache dependencies |
โ
OpenShift uses these scripts automatically when you run oc new-app.
You donโt have to write Dockerfiles manually!
๐ S2I Full Flow (Visual)
Your GitHub Repo (HTML / PHP / Python App)
โ
+-------------------+
| S2I Base Image |
| (nginx, python) |
+-------------------+
โ
OpenShift S2I Process (BuildConfig)
โ
New Image (runtime + your code together)
โ
Pod runs your application!
Code language: PHP (php)
๐ฅ When to use S2I
| Use S2I if… | Reason |
|---|---|
| You have app source code (HTML, PHP, Node.js, Python, etc.) | Easy auto-build |
| You don’t want to write Dockerfiles manually | Saves your time |
| You want to build and deploy faster inside OpenShift | Automated pipelines |
โ S2I is powerful especially for development workflows and CI/CD pipelines.
โจ In one simple sentence:
S2I Base Image is a starting point container that expects your source code and creates a ready-to-run application image automatically inside OpenShift.
๐ Summary Table:
| Term | Meaning |
|---|---|
| S2I | Source-to-Image build process |
| S2I Base Image | Pre-built image waiting for your code |
| Used for | Automating app builds inside OpenShift |
| Needs Source Code? | โ Yes |
| Runs directly as pod? | โ No, needs build step first |
๐ Practical Tip for You
| Scenario | What to use |
|---|---|
| Want to run simple nginx server quickly | Use nginxinc/nginx-unprivileged |
| Want to build HTML app and serve | Use rhscl/nginx-116-rhel7 as S2I |
๐ฏ Running an S2I Base Image in OpenShift Cluster
โ
Beginner-friendly
โ
Realistic example
โ
Works on OpenShift 4.x or later
๐ฆ S2I Tutorial Overview
We will:
| Step | Task | Description |
|---|---|---|
| 1 | Pick an S2I base image | Example: registry.redhat.io/rhscl/nginx-116-rhel7 |
| 2 | Prepare simple source code | HTML project on GitHub |
| 3 | Create S2I app in OpenShift | Using oc new-app |
| 4 | Deploy and access app | Via OpenShift Route |
๐ Step 1: Pick an S2I Base Image
We will use:
registry.redhat.io/rhscl/nginx-116-rhel7
โ Itโs an NGINX S2I builder (for serving static websites).
๐งฐ Step 2: Prepare Source Code (GitHub)
You need a GitHub repo with static website files (HTML/CSS).
Example ready-to-use repo:
โก๏ธ https://github.com/sclorg/nginx-container/tree/master/1.16/test/test-app/
Or you can create your own repo like this:
- Create a new GitHub repo:
Example:https://github.com/yourusername/my-s2i-nginx-app - Add some simple
index.html:
<!-- index.html -->
<html>
<head><title>Welcome to S2I NGINX App</title></head>
<body><h1>Hello from OpenShift + S2I!</h1></body>
</html>
Code language: HTML, XML (xml)
โ Push this file to GitHub.
๐ Step 3: Create S2I App in OpenShift
๐ Login to your OpenShift cluster:
oc login https://your-openshift-cluster:6443
Code language: JavaScript (javascript)
๐ Now create your S2I app:
oc new-app registry.redhat.io/rhscl/nginx-116-rhel7~https://github.com/yourusername/my-s2i-nginx-app --strategy=source
Code language: JavaScript (javascript)
โ What this command does:
- Pulls base image
nginx-116-rhel7 - Pulls your source code from GitHub
- Builds a new image combining both
- Deploys a pod automatically
๐ Step 4: Expose Route (to Access App)
Create a Route:
oc expose svc/my-s2i-nginx-app
โ Then get the URL:
oc get routes
Code language: JavaScript (javascript)
You’ll get something like:
http://my-s2i-nginx-app-yourproject.apps.cluster.example.com
Code language: JavaScript (javascript)
Open it in browser โ
โจ You will see your HTML page served from the new OpenShift app!
๐ Full Commands Summary
# Login
oc login https://your-openshift-cluster:6443
# Create S2I app
oc new-app registry.redhat.io/rhscl/nginx-116-rhel7~https://github.com/yourusername/my-s2i-nginx-app --strategy=source
# (Optional) Watch build
oc logs -f bc/my-s2i-nginx-app
# Expose a Route
oc expose svc/my-s2i-nginx-app
# Get public URL
oc get routes
Code language: PHP (php)
๐ฅ Important Tips
| Problem | Solution |
|---|---|
error: cannot find source repository | Check GitHub URL is public |
imagepullbackoff | Check cluster can pull Red Hat registry images (pull secret) |
| App not updating? | Run oc start-build my-s2i-nginx-app --from-dir=. to rebuild manually |
๐ง Visual Flow
GitHub Repo (HTML)
โ
oc new-app (S2I build)
โ
BuildConfig + ImageStream created
โ
Pod created from new image
โ
Service + Route exposed
โ
Your app live on internet! ๐
Code language: JavaScript (javascript)
๐ Final Quick Recap
| Step | Action |
|---|---|
| 1 | Pick S2I builder (registry.redhat.io/rhscl/nginx-116-rhel7) |
| 2 | Prepare GitHub repo (index.html) |
| 3 | Run oc new-app with --strategy=source |
| 4 | Expose service using Route |
โ
You now know how to run S2I base images in OpenShift!
โ
This knowledge is essential for DevOps, OpenShift developers, CI/CD engineers.
Letโs do a real complete project:
Youโll build your own HTML website,
then deploy it into OpenShift using S2I process.
๐ฏ Project Goal
| Step | Action |
|---|---|
| 1 | Create a simple HTML website |
| 2 | Push the website to GitHub |
| 3 | Deploy it into OpenShift using S2I base image |
| 4 | Access your site via OpenShift Route |
๐ Step 1: Create Your Own HTML Website
On your local machine, create a project:
mkdir my-openshift-website
cd my-openshift-website
Now create a simple index.html:
<!-- my-openshift-website/index.html -->
<html>
<head>
<title>Welcome to My OpenShift Website</title>
</head>
<body>
<h1>Hello World from Rajesh! ๐</h1>
<p>Running on OpenShift with S2I magic!</p>
</body>
</html>
Code language: HTML, XML (xml)
โ Done โ your website is ready.
๐ Step 2: Push Your Website to GitHub
Initialize Git and push:
git init
git add .
git commit -m "Initial commit - my openshift html site"
git branch -M main
git remote add origin https://github.com/yourusername/my-openshift-website.git
git push -u origin main
Code language: JavaScript (javascript)
โ Now your project is live at:
https://github.com/yourusername/my-openshift-website
Code language: JavaScript (javascript)
(Public GitHub repo needed for OpenShift to pull.)
๐ Step 3: Deploy to OpenShift Using S2I
โ Login to your OpenShift cluster:
oc login https://your-openshift-cluster:6443
Code language: JavaScript (javascript)
โ Now run S2I Deployment:
oc new-app registry.redhat.io/rhscl/nginx-116-rhel7~https://github.com/yourusername/my-openshift-website --strategy=source
Code language: JavaScript (javascript)
โ OpenShift will:
- Pull NGINX S2I base image (
rhscl/nginx-116-rhel7) - Pull your HTML website from GitHub
- Build a new container image
- Deploy a Pod automatically
โ Watch the build logs (optional):
oc logs -f bc/my-openshift-website
๐ Step 4: Expose your app with a Route
โ Create a Route:
oc expose svc/my-openshift-website
โ Get the public URL:
oc get routes
Code language: JavaScript (javascript)
Youโll get something like:
http://my-openshift-website-myproject.apps.cluster.example.com
Code language: JavaScript (javascript)
โ Open this URL in browser!
๐ Youโll see:
Hello World from Rajesh! ๐
Running on OpenShift with S2I magic!
Code language: JavaScript (javascript)
โ Your custom HTML website is now live on OpenShift! ๐
๐ Full Commands Summary (Cheat Sheet)
# 1. Create HTML site
mkdir my-openshift-website && cd my-openshift-website
# (create index.html)
# 2. Push to GitHub
git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/yourusername/my-openshift-website.git
git push -u origin main
# 3. Deploy to OpenShift
oc login https://your-openshift-cluster:6443
oc new-app registry.redhat.io/rhscl/nginx-116-rhel7~https://github.com/yourusername/my-openshift-website --strategy=source
# 4. Watch build (optional)
oc logs -f bc/my-openshift-website
# 5. Expose
oc expose svc/my-openshift-website
# 6. Get URL
oc get routes
Code language: PHP (php)
๐ง Visual Architecture
Your GitHub Repo (index.html)
โ
S2I Build Process (oc new-app)
โ
BuildConfig + ImageStream
โ
New Container Image Created
โ
Pod Running + Service
โ
Route Created
โ
Public Website LIVE ๐
Code language: PHP (php)
๐ข Key Points to Remember
| Topic | Tip |
|---|---|
| Base Image | registry.redhat.io/rhscl/nginx-116-rhel7 |
| Strategy | --strategy=source |
| Code Location | Public GitHub repo |
| Exposing service | Use oc expose svc/<service-name> |
| Cluster pull secrets | Must be able to pull Red Hat registry images |
๐ Now you know how to:
โ
Create your own HTML app
โ
Deploy it into OpenShift using S2I
โ
Access it publicly over internet
โ
Automate build from GitHub source
โ
Master basic OpenShift developer workflow ๐
Iโm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at WIZBRAND
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals