Chapter 2. Creating container images in a network-restricted environment
As an application developer, configure OpenShift Container Platform with an HTTP or HTTPS proxy to enforce security and prevent direct internet access for your build processes. This setup enforces security by routing build pulls of dependencies, images, and code through a monitored outgoing proxy gateway.
2.1. Creating a buildah build in a network-restricted environment Copy linkLink copied to clipboard!
Create a buildah build in a network-restricted environment by mirroring the images that buildah build strategy requires. Mirroring the images eliminates the need for public registry access. This ensures clusters use only images that comply with external content controls.
Prerequisites
- You have installed the Builds for Red Hat OpenShift Operator on the OpenShift Container Platform cluster.
-
You have installed the
ocCLI. -
Optional: You have installed the
shpCLI. - Your cluster can connect and interact with the Git source that you can use to create the buildah build.
-
You have the builder-image required to create the
buildahbuild in your local registry. If the builder-image is not present in the local registry, mirror the source image.
Procedure
Run the following command to mirror the images that
buildahbuild strategy requires:$ oc image mirror --insecure -a <registry_authentication> registry.redhat.io/ubi8/buildah@sha256:1c89cc3cab0ac0fc7387c1fe5e63443468219aab6fd531c8dad6d22fd999819e <mirror_registry>/<repo>/ubi8_buildahwhere:
<registry_authentication>- Specifies the authentication credentials used to access a container registry. This is required when pushing to or pulling from a private registry.
<mirror_registry>- Specifies the registry where the image you want to mirror is stored.
Create a
Buildresource and apply it to the OpenShift Container Platform cluster. You can do so by using theoccommand or theshpcommand:$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: Build metadata: name: buildah-golang-build spec: source: type: Git git: url: https://github.com/shipwright-io/sample-go contextDir: docker-build strategy: name: buildah kind: ClusterBuildStrategy paramValues: - name: dockerfile value: Dockerfile output: image: image-registry.openshift-image-registry.svc:5000/buildah-example/sample-go-app EOFwhere:
source- Defines the location where the source code is placed.
strategy- Defines the build strategy that you use to build the container.
paramValues-
Defines the parameter defined in the build strategy. To set the value of the
dockerfilestrategy parameter, specify the Dockerfile location required to build the output image. output-
Defines the location where the built image is pushed. In this procedural example, the built image is pushed to the OpenShift Container Platform cluster internal registry.
buildah-exampleis the name of the current project. Ensure that the specified project exists to allow the image push.
$ shp build create buildah-golang-build \ --source-url="https://github.com/redhat-openshift-builds/samples" --source-context-dir="buildah-build" \ --strategy-name="buildah" \ --dockerfile="Dockerfile" \ --output-image="image-registry.openshift-image-registry.svc:5000/buildah-example/go-app"where:
source-context-dir- Defines the location where the source code is placed.
strategy-name- Defines the build strategy that you use to build the container.
dockerfile-
Defines the parameter defined in the build strategy. To set the value of the
dockerfilestrategy parameter, specifies the Dockerfile location required to build the output image. output-image-
Defines the location where the built image is pushed. In this procedural example, the built image is pushed to the OpenShift Container Platform cluster internal registry.
buildah-exampleis the name of the current project. Ensure that the specified project exists to allow the image push.
Check if the
Buildresource is created. You can do so by using theoccommand or theshpcommand:$ oc get builds.shipwright.io buildah-golang-build$ shp build listCreate a
BuildRunresource and apply it to the OpenShift Container Platform cluster. You can do so by using theoccommand or theshpcommand:$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: BuildRun metadata: name: buildah-golang-buildrun spec: build: name: buildah-golang-build EOFwhere:
spec.build.name- Defines the build to run, which is expected to be available in the same namespace.
$ shp build run buildah-golang-build --follow-
--follow:: (Optional) Use the--followflag to view the build logs in the output result.
Check if the
BuildRunresource is created. You can do so by using theoccommand or theshpcommand:$ oc get buildrun buildah-golang-buildrun$ shp buildrun listThe
BuildRunresource creates aTaskRunresource, which then creates the pods to execute build strategy steps.
Verification
After all the containers complete their tasks, verify the following resources:
Check whether the pod shows the
STATUSfield asCompleted:$ oc get pods -wExample output:
NAME READY STATUS RESTARTS AGE buildah-golang-buildrun-dtrg2-pod 2/2 Running 0 4s buildah-golang-buildrun-dtrg2-pod 1/2 NotReady 0 7s buildah-golang-buildrun-dtrg2-pod 0/2 Completed 0 55sCheck whether the respective
TaskRunresource shows theSUCCEEDEDfield asTrue:$ oc get trExample output:
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME buildah-golang-buildrun-dtrg2 True Succeeded 11m 8m51sCheck whether the respective
BuildRunresource shows theSUCCEEDEDfield asTrue:$ oc get brExample output:
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME buildah-golang-buildrun True Succeeded 13m 11mDuring verification, if a build run fails, you can check the
status.failureDetailsfield in yourBuildRunresource to identify the exact point where the failure happened in the pod or container.NoteThe pod might switch to a
NotReadystate because one of the containers has completed its task. This is an expected behavior.Validate whether the image has been pushed to the registry that is specified in the
build.spec.output.imagefield. Run the following command to pull the image from a node that can access the internal registry:$ podman manifest inspect image-registry.openshift-image-registry.svc:5000/buildah-example/taxi-appIn the previous example, the project name is
buildah-example, and the image name istaxi-app.Example output:
"schemaVersion": 2, "mediaType": "application/vnd.docker.distribution.manifest.v2+json", "manifests": [ { "mediaType": "application/vnd.docker.distribution.manifest.v2+json", "size": 594, "digest": "sha256:6a05100e302c86c03fec6277f4b3107f1fdde6c69d3ca9a4207e4735a5213e32", "platform": { "architecture": "amd64", "os": "linux" } ]
2.2. Creating a source-to-image build in a network-restricted environment Copy linkLink copied to clipboard!
Use the source-to-image build strategy in disconnected environments by first mirroring required builder images to a local registry. This approach allows your cluster to operate without public registry access while maintaining compliance with organizational content policies.
Prerequisites
- You have installed the Builds for Red Hat OpenShift Operator on the OpenShift Container Platform cluster.
-
You have installed the
ocCLI. -
Optional: You have installed the
shpCLI. - Your cluster can connect and interact with the Git source that you can use to create the source-to-image build.
-
You have the builder-image required to create the
source-to-imagebuild in your local registry. If the builder-image is not present in the local registry, mirror the source image.
Procedure
Run the following command to mirror the images that
source-to-imagebuild strategy requires:$ oc image mirror --insecure -a <registry_authentication> registry.redhat.io/source-to-image/source-to-image-rhel8@sha256:d041c1bbe503d152d0759598f79802e257816d674b342670ef61c6f9e6d401c5 <mirror_registry>/<repo>/source-to-image-source-to-image-rhel8where:
<registry_authentication>- Specifies the authentication credentials used to access a container registry. This is required when pushing to or pulling from a private registry.
<mirror_registry>- Specifies the registry where the image you want to mirror is stored.
Create a
Buildresource and apply it to the OpenShift Container Platform cluster. You can do so by using theoccommand or theshpcommand:$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: Build metadata: name: s2i-nodejs-build spec: source: type: Git git: url: https://github.com/redhat-openshift-builds/samples contextDir: s2i-build/nodejs strategy: name: source-to-image kind: ClusterBuildStrategy paramValues: - name: builder-image value: quay.io/centos7/nodejs-12-centos7:master output: image: quay.io/<repo>/s2i-nodejs-example pushSecret: registry-credential EOFwhere:
source- Defines the location where the source code is placed.
strategy- Defines the build strategy that you use to build the container.
paramValues-
Defines the parameters for the build strategy. For
source-to-imagebuilds, this includes thebuilder-imageparameter that specifies the base image used to build your application. output-
Defines the location where the built image is pushed. In this procedural example, the built image is pushed to the OpenShift Container Platform cluster internal registry.
buildah-exampleis the name of the current project. Ensure that the specified project exists to allow the image push. pushSecret-
Defines the secret name that stores the credentials for pushing container images. To generate a secret of the type
docker-registryfor authentication, see "Authentication to container registries".
$ shp build create s2i-nodejs-build \ --source-url="https://github.com/redhat-openshift-builds/samples" --source-context-dir="s2i-build/nodejs" \ --strategy-name="source-to-image" \ --builder-image="quay.io/centos7/nodejs-12-centos7" \ --output-image="quay.io/<repo>/s2i-nodejs-example" \ --output-credentials-secret="registry-credential"where:
source-context-dir- Defines the location where the source code is placed.
strategy-name- The build strategy that you use to build the container.
builder-image-
The parameter defined in the build strategy. For
source-to-imagebuilds, this specifies the base image used to build your application. output-image-
The location where the built image is pushed. In this procedural example, the built image is pushed to the OpenShift Container Platform cluster internal registry.
buildah-exampleis the name of the current project. Ensure that the specified project exists to allow the image push. output-credentials-secret-
The secret name that stores the credentials for pushing container images. To generate a secret of the type
docker-registryfor authentication, see "Authentication to container registries".
Check if the
Buildresource is created. You can do so by using theoccommand or theshpcommand:$ oc get builds.shipwright.io s2i-nodejs-build$ shp build listCreate a
BuildRunresource and apply it to the OpenShift Container Platform cluster. You can do so by using theoccommand or theshpcommand:$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: BuildRun metadata: name: s2i-nodejs-buildrun spec: build: name: s2i-nodejs-build EOFwhere:
spec.build.name- Specifies the respective build to run, which is expected to be available in the same namespace.
$ shp build run s2i-nodejs-build --follow+ where:
--follow-
(Optional) Use the
--followflag to view the build logs in the output result.
Check if the
BuildRunresource is created. You can do so by using theoccommand or theshpcommand:$ oc get buildrun s2i-nodejs-buildrun$ shp buildrun listThe
BuildRunresource creates aTaskRunresource, which then creates the pods to execute build strategy steps.
Verification
After all the containers complete their tasks, verify the statuses of the following resources:
Check whether the pod shows the
STATUSfield asCompleted:$ oc get pods -wExample output:
NAME READY STATUS RESTARTS AGE s2i-nodejs-buildrun-phxxm-pod 2/2 Running 0 10s s2i-nodejs-buildrun-phxxm-pod 1/2 NotReady 0 14s s2i-nodejs-buildrun-phxxm-pod 0/2 Completed 0 2mCheck whether the respective
TaskRunresource shows theSUCCEEDEDfield asTrue:$ oc get trExample output:
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME s2i-nodejs-buildrun-phxxm True Succeeded 2m39s 13sCheck whether the respective
BuildRunresource shows theSUCCEEDEDfield asTrue:$ oc get brExample output:
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME s2i-nodejs-buildrun True Succeeded 2m41s 15sDuring verification, if a build run fails, you can check the
status.failureDetailsfield in yourBuildRunresource to identify the exact point where the failure happened in the pod or container.NoteThe pod might switch to a
NotReadystate because one of the containers has completed its task. This is an expected behavior.Validate whether the image has been pushed to the registry that is specified in the
build.spec.output.imagefield. Log in to the registry and run the following command to pull the image:$ podman manifest inspect image-registry.openshift-image-registry.svc:5000/s2i-example/taxi-appIn the previous example, the project name is
s2i-example, and the image name istaxi-app.Example output:
"schemaVersion": 2, "mediaType": "application/vnd.docker.distribution.manifest.v2+json", "manifests": [ { "mediaType": "application/vnd.docker.distribution.manifest.v2+json", "size": 594, "digest": "sha256:6a05100e302c86c03fec6277f4b3107f1fdde6c69d3ca9a4207e4735a5213e32", "platform": { "architecture": "amd64", "os": "linux" } ]
2.3. Verifying proxy details Copy linkLink copied to clipboard!
If you run a cluster behind a proxy, ensure that cluster-wide proxy settings and environment variables are correctly configured in the OpenShift Container Platform cluster. This ensures all Builds traffic is routed through the monitored outbound proxy gateway.
Prerequisites
-
You have installed the
ocCLI.
Procedure
To verify the cluster-wide proxy settings, run the following command:
$ oc describe proxy/clusterExample output:
Name: cluster Namespace: Labels: hypershift.openshift.io/managed=true Annotations: hypershift.io/hosted-cluster-proxy-config: true include.release.openshift.io/ibm-cloud-managed: true include.release.openshift.io/self-managed-high-availability: true release.openshift.io/create-only: true API Version: config.openshift.io/v1 Kind: Proxy Metadata: Creation Timestamp: 2026-01-05T09:56:06Z Generation: 2 Owner References: API Version: config.openshift.io/v1 Kind: ClusterVersion Name: version UID: bfb9588f-106f-4e9f-965b-03daa0cd8c33 Resource Version: 1451 UID: 8bbf0aef-6d78-479d-abdf-ddbb34bf3ff1 Spec: Trusted CA: Name: Events: <none>To verify the environment variables, run the following command:
$ oc set env deployment/openshift-builds-operator --list -n openshift-builds | grep PROXYExample output:
HTTP_PROXY=http://192.168.130.1:3128 HTTPS_PROXY=https://192.168.130.1:3129 NO_PROXY=.cluster.local,.svc,.testing,10.217.0.0/22,10.217.4.0/23,127.0.0.1,192.168.126.0/24,192.168.1 30.11,api-int.crc.testing,localhost