π― 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!
π₯ 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>
β Push this file to GitHub.
π Step 3: Create S2I App in OpenShift
π Login to your OpenShift cluster:
oc login https://your-openshift-cluster:6443
π 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
β 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
You’ll get something like:
http://my-s2i-nginx-app-yourproject.apps.cluster.example.com
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
π₯ 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! π
π 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>
β 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
β Now your project is live at:
https://github.com/yourusername/my-openshift-website
(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
β Now run S2I Deployment:
oc new-app registry.redhat.io/rhscl/nginx-116-rhel7~https://github.com/yourusername/my-openshift-website --strategy=source
β 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
Youβll get something like:
http://my-openshift-website-myproject.apps.cluster.example.com
β Open this URL in browser!
π Youβll see:
Hello World from Rajesh! π
Running on OpenShift with S2I magic!
β 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
π§ 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 π
π’ 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 am working at Cotocus. I blog tech insights 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 I reviewed , 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 PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND