How to Connect OpenShift BuildConfig to Docker Hub

On this article im trying to use Openshift as a Build Server to build a containerized image from a plain sourcecode and store the result in external Image Registry, in this case Docker Hub. The goal is to provide another options to build containerized image when we have limitation, especially we dont have any Docker command installed in our local laptop.

The concept is displayed in below image,

For this example, im using a simple PHP file.

<?php
    echo "hello world php";
?>

So lets start by creating a BuildConfig to containerized this PHP code in OpenShift, and trigger it by using our local PHP file,

 $ oc new-build . --name=hello-world-php --to-docker \ 
		--to=docker.io/dockerusername/hello-world-php

 $ oc start-build hello-world-php \ 
		--from-dir=. --follow --wait

But before we do that, we need to register our Docker Hub credentials into our OCP so that OCP can push the build image into Docker Hub.

 $ oc create secret docker-registry --docker-server=docker.io \ 
		--docker-username=dockerusername --docker-password=dockerpassword 
		--docker-email=your@email.com docker-login

 $ oc secret link builder docker-login --for=mount

In summary, there are multiple ways and strategies of deploying your app into OpenShift and this is one way of doing it.

Leave a Comment

Your email address will not be published.