Build and deploy from source with oc new-app and Source-to-Image
How oc new-app turns a Git repository or an image into a running app, how Source-to-Image and Docker builds are chosen, and how to manage BuildConfigs, image streams and rebuilds.
Not checked by a trusted editor yet Last edited Outdated?
oc new-app is OpenShift’s shortcut for getting something running. Give it an image, a Git repository or a template and it generates the objects needed to build and run it. Behind it are two OpenShift-specific resources: the BuildConfig, which describes how to produce an image, and the image stream, which tracks the images produced.
From an existing image
oc new-app registry.access.redhat.com/ubi9/httpd-24 --name=static
oc new-app myregistry.example.com:5000/team/api:1.4 --name=api
oc new-app my-stream:v1
This creates a Deployment and, if the image declares exposed ports, a Service. Current oc releases create a Kubernetes Deployment; DeploymentConfig objects are deprecated since OpenShift 4.14, and --as-deployment-config only exists for old setups.
From source code with S2I
Source-to-Image (S2I) produces a ready-to-run image by injecting your source into a builder image that knows how to assemble it, for example by installing Python requirements or running npm install. You do not need a Dockerfile.
# Name the builder explicitly with builder~repository
oc new-app registry.access.redhat.com/ubi9/python-311~https://github.com/sclorg/django-ex.git#4.2.x --name=web
# Let oc detect the language (needs git installed locally)
oc new-app https://github.com/sclorg/httpd-ex.git
# A subdirectory and a private repository
oc new-app https://github.com/example/monorepo.git --context-dir=services/api --source-secret=git-cred
How the build strategy is chosen
- If the repository root (or
--context-dir) has aDockerfile,oc new-appcreates a Docker build, which OpenShift runs with Buildah. - If it has a
Jenkinsfile, it creates a pipeline build. That strategy is deprecated in favor of OpenShift Pipelines (Tekton). - Otherwise it creates a Source (S2I) build and picks a builder from marker files:
package.jsonfor Node.js,requirements.txtorsetup.pyfor Python,pom.xmlfor Java,composer.jsonorindex.phpfor PHP,Gemfilefor Ruby,main.gofor Go. - With the
builder~repositoryform, detection is skipped. Override the guess with--strategy=dockeror--strategy=source.
Language detection looks for matching image streams on the cluster, typically in the openshift namespace. Run oc get imagestreams -n openshift to see what builders your cluster offers; the Cluster Samples Operator that installs them is deprecated and may be set to Removed, so naming the builder image explicitly is more predictable.
Pass settings at creation time
oc new-app registry.access.redhat.com/ubi9/python-311~https://github.com/example/api.git \
--name=api \
-e APP_MODE=production \
--build-env PIP_INDEX_URL=https://pypi.example.com/simple \
-l app.kubernetes.io/part-of=shop
-e sets runtime environment variables on the deployment, and --build-env sets variables only during the build. Put real secrets in a Secret afterward rather than on the command line.
Follow, restart and debug builds
oc get bc,builds
oc logs -f bc/web # follow the latest build
oc start-build web --follow # start a new build and stream it
oc start-build web --from-dir=. # build from local files, no git push needed
oc cancel-build bc/web
oc describe build web-3 # status, reason and events
A build runs in a pod, so common failures look familiar: a typo in the Git URL, a missing source secret for a private repository, a dependency download blocked by a proxy (set HTTP_PROXY with --build-env), or a builder image that cannot be pulled.
Image streams and automatic rollouts
An image stream does not store image data. It is a named view of image references, and builds and deployments can point at an image stream tag such as web:latest. When a build pushes a new image to that tag, the deployment created by oc new-app is triggered and rolls out the new image.
oc get is web
oc describe is web
oc tag web:latest web:approved # promote a build by tagging
oc import-image python-311 --from=registry.access.redhat.com/ubi9/python-311:latest --confirm
Next step: publish it
oc new-app never creates a route. Publish the service with oc expose service/web for plain HTTP, or with oc create route edge for HTTPS.
Official documentation
See also
- 0150 Logging in with oc and working with OpenShift projects Install the oc client, log in with a password, browser or token, then create, switch and inspect projects. Covers where oc stores… Beginner · How-to · Any system Article Concepts · Deploying applications 15 Oct 2026
- 0151 Tutorial: deploy a small web app on OpenShift and expose it with a Route A step-by-step first deployment: create a project, build a static website from Git with Source-to-Image, publish it on an HTTPS Route, then… Beginner · How-to · Any system Article Deploying applications 15 Oct 2026
- 0153 Expose apps with OpenShift Routes: edge, passthrough and re-encrypt TLS A Route publishes a service on a host name through the OpenShift router. Learn when to use plain HTTP, edge, passthrough or… Intermediate · How-to · Any system Article Deploying applications · Ingress & networking 15 Oct 2026
- 0154 OpenShift app configuration: environment, ConfigMaps, Secrets and persistent storage Set environment variables, load ConfigMaps and Secrets into a Deployment as variables or files, and give it persistent storage with a PersistentVolumeClaim,… Intermediate · How-to · Any system Article Config, secrets & storage · Deploying applications 15 Oct 2026
- 0157 oc cheat sheet: everyday OpenShift CLI commands The oc commands you use every day, grouped by task: login and projects, apps and builds, routes, config, debugging, permissions and admin… Intermediate · Reference · Any system Article Deploying applications · Troubleshooting 15 Oct 2026
- 0158 Collect an OpenShift project report with oc A read-only bash script that gathers a project's workloads, pods, routes, builds, storage and warning events, plus describe output and logs of… Intermediate · How-to · Linux, macOS Script Deploying applications · Troubleshooting 15 Oct 2026
Repos in the wild
- openshift/oc: the OpenShift command line client openshift/oc Source code of oc, the OpenShift CLI. It is built on top of kubectl, so it can do everything kubectl does, and adds commands for projects, builds, routes, image streams and cluster administration. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Commitpedia +4,308 chars