Normally a S2I docker image already has all the basic components to develop most applications, but there is always that coworker who uses an obscure library to do our daily quick-and-dirty fix.
To not leave this crowd without our favorite build tool, I will show you how easy, fast, and cheap it is to customize an S2I image builder.
You will need:
S2i image build source code — I will use php because it is the most popular language in the universe
The name of the package, binary, or whatever you intend to install in the image
Let's start by doing the setup. Download the source code to generate the image you chose. At Getup Cloud, we basically use the official images of the Software Collections project, available on the project's Github. However, we have our own S2I image for PHP 7, and that's the one we'll use in this tutorial.
$ git clone https://github.com/getupcloud/sti-php.git
$ cd sti-php
The Dockerfile for version 7.0 should look something like the gist below:
https://gist.github.com/caruccio/9af565bdf6e3f9721ca62893b2a3f098
Let's do a first build:
$ cd 7.0
$ docker build . -t custom-php7
Including new packages
We're simply going to extend this image and add our packages. For this, let's first find out the name:tag of the image used here at Getup:
$ oc describe imagestream/php -n openshift
Name: php
Namespace: openshift
Created: 11 months ago
Labels: <none>
Annotations: openshift.io/image.dockerRepositoryCheck=2016-10-27T20:30:04Z
Docker Pull Spec: 172.30.34.145:5000/openshift/php
Unique Images: 28
Tags: 4
7.0
tagged from getupcloud/php-70-centos7:latest
...
Now we can create our Dockerfile in another directory:
$ mkdir custom-php7
$ cd custom-php7
$ cat Dockerfile
# Using getup's official image as a base
FROM getupcloud/php-70-centos7:latest
# We need to switch to root before installing anything
USER root
# We install our dependency
RUN yum install -y --enablerepo=remi-php70 php-devel && \
yum clean all -y && \
pecl install zip && \
pecl clear-cache && \
echo "extension=zip.so" >> /etc/php.ini
# And switch back to the default user
USER 1001
Building our custom-built image (custom-php7) requires a build:
$ docker build -t custom-php7 .
To verify that the zip library was indeed installed, you can create a container and check the output of pecl list:
$ docker run -it --rm custom-php7 bash
bash-4.2# pecl list | grep zip
zip 1.13.5 stable
bash-4.2# exit
To test, we can use the s2i command and build our application locally before sending it to DockerHub (learn more about s2i in the article Docker — from code to image with S2I)
$ cat index.php
<?php phpinfo(); ?>
$ s2i build --copy . custom-php7 custom-app
$ docker run -it --rm -p 8080:8080 custom-app
Access the container in your browser at http://127.0.0.1:8080 and look for "Zip version".
Publish on Getup
Now that we have our custom ImageBuilder for php7, used by s2i to build application images, we can send it to DockerHub. It is from there that the Getup platform pulls images to run.
For this you will need a DockerHub account. Go there, sign up and come back here…
Now log in with your docker client and tag the latest build:
$ docker login
$ docker tag custom-php7 ${DOCKERHUB_LOGIN}/custom-php7:latest
$ docker push ${DOCKERHUB_LOGIN}/custom-php7:latest
Replace ${DOCKERHUB_LOGIN} with your DockerHub login
Pro tip: You can build and tag at the same time: docker build -t ${DOCKERHUB_LOGIN}/custom-php7:latest .
As a last step, let's create an ImageStream that uses this docker image in your Getup account.
The ImageStream is a configuration that groups and tracks docker images. It is a default OpenShift object and allows automatically triggering builds for your applications when a tracked docker image is updated and re-imported into the platform.
$ cat custom-php7-imagestream.yaml
apiVersion: v1
kind: ImageStream
metadata:
name: custom-php7
spec:
tags:
- name: "7.0"
annotations:
description: My Custom PHP-7 ImageBuilder
iconClass: icon-php
sampleRepo: https://github.com/openshift/cakephp-ex.git
supports: php:7.0,php
tags: builder,php
version: "7.0"
from:
kind: DockerImage
name: ${DOCKERHUB_LOGIN}/custom-php7:latest
- name: latest
annotations:
description: My Custom PHP-7 ImageBuilder
iconClass: icon-php
sampleRepo: https://github.com/openshift/cakephp-ex.git
supports: php:7.0,php
tags: builder,php
version: "latest"
from:
kind: ImageStreamTag
name: "7.0"
From this point forward you will need the oc command — https://ajuda.getupcloud.com/hc/pt-br/articles/221403968
Let's create our ImageStream inside our project:
$ oc create -f custom-php7-imagestream.yaml
Note that you must replace the value of ${DOCKERHUB_LOGIN} in the file above
The final step is to trigger the import of this image into Getup's OpenShift platform:
$ oc import-image custom-php7
Done! From now on you can build your PHP7 app from your custom PHP ImageBuilder. Access https://portal.getupcloud.com and create a new application.
Tips
If you need to change anything in the builder image (add, edit or remove a docker layer), you will need to:
Recreate the image locally (docker build…)
Move the tag (docker tag…)
Send to dockerhub (docker push…)
Import into Getup (oc import-image…)
To alter the ImageStream (custom-php7-imagestream.yaml) you only need to edit the file locally and use the command oc replace custom-php7-imagestream.yaml. If the change involves the docker image (changing the tag, repository, name, etc.) it will be necessary to re-import it into the platform (see step 4 above).
[embed]https://upscri.be/375ca4/[/embed]
Newsletter Getup.
Atualizações sobre Kubernetes e Software Supply Chain Security todos os meses.
Operating Kubernetes in production for more than 13 years. With Quor, this experience extends to software supply chain security as well.
GET UP
© Getup · 2026

