Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOpsSchool!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

What is Openshift S2I?


🎯 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:

FeatureDescription
Has a web server, app server, or runtime pre-installede.g., nginx, nodejs, python
Has scripts inside (assemble, run)Helps OpenShift build a new app image automatically
Waits for your source codeYour app code is injected during build
Produces a new runnable imageCombining 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 WayS2I Way
You manually build Docker image (nginx + your site files)You push your HTML files to GitHub
You write Dockerfile yourselfOpenShift runs oc new-app nginx-s2i~your-git-repo
You manually build/push containerOpenShift builds everything automatically

Less work for you ✅ More automation for you


📢 Example of S2I base images:

Base ImageLanguage/RuntimeUsage
registry.redhat.io/rhscl/nginx-116-rhel7nginxServe HTML sites
registry.redhat.io/rhscl/nodejs-14-rhel7Node.js 14Node.js apps
registry.redhat.io/rhscl/python-38-rhel7Python 3.8Python apps
registry.redhat.io/rhscl/php-73-rhel7PHP 7.3PHP apps

All these are S2I base images.


📋 How an S2I base image actually works inside:

It includes scripts like:

ScriptPurpose
assembleHow to copy your source code into the container and prepare the app
runHow to start the server when container runs
save-artifactsOptional, 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 manuallySaves your time
You want to build and deploy faster inside OpenShiftAutomated 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:

TermMeaning
S2ISource-to-Image build process
S2I Base ImagePre-built image waiting for your code
Used forAutomating app builds inside OpenShift
Needs Source Code?✅ Yes
Runs directly as pod?❌ No, needs build step first

🚀 Practical Tip for You

ScenarioWhat to use
Want to run simple nginx server quicklyUse nginxinc/nginx-unprivileged
Want to build HTML app and serveUse 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:

StepTaskDescription
1Pick an S2I base imageExample: registry.redhat.io/rhscl/nginx-116-rhel7
2Prepare simple source codeHTML project on GitHub
3Create S2I app in OpenShiftUsing oc new-app
4Deploy and access appVia 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:

  1. Create a new GitHub repo:
    Example: https://github.com/yourusername/my-s2i-nginx-app
  2. 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

ProblemSolution
error: cannot find source repositoryCheck GitHub URL is public
imagepullbackoffCheck 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

StepAction
1Pick S2I builder (registry.redhat.io/rhscl/nginx-116-rhel7)
2Prepare GitHub repo (index.html)
3Run oc new-app with --strategy=source
4Expose 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

StepAction
1Create a simple HTML website
2Push the website to GitHub
3Deploy it into OpenShift using S2I base image
4Access 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

TopicTip
Base Imageregistry.redhat.io/rhscl/nginx-116-rhel7
Strategy--strategy=source
Code LocationPublic GitHub repo
Exposing serviceUse oc expose svc/<service-name>
Cluster pull secretsMust 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 🚀


Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x