Bootstrap FreeKB - OpenShift - Deploy an application from Docker Hub
OpenShift - Deploy an application from Docker Hub

Updated:   |  OpenShift articles

An image contains the code used to create a deployment. Then, a deployment can be created from an image, which should then create a replica set (which is the number of pods that should be created), and then the pods should be created.

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

The oc new-app or oc create command can be used to deploy an application from Docker Hub to OpenShift.

There are various ways to deploy an app.


From Docker Hub

On Docker Hub, there is a image named hello-world.

The oc get images command can be used to determine if the image has already been pulled down. If the image has already been pulled down, something like this should be returned.

~]# oc get images
NAME                                                                      DOCKER REF
sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4   hello-world@sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4

 

The oc get imagestreams command can be used to see if the image has already been deployed in your currently selected project / namespace. In this scenario, the application will be obtained from the image stream, meaning that the image will not be pulled down from Docker Hub. If you want to pull the image from Docker Hub, you may need to delete the image stream and the image too.

~]$ oc get imagestream hello-world
NAME          IMAGE REPOSITORY                                                       TAGS    UPDATED
hello-world   image-registry.openshift-image-registry.svc:5000/default/hello-world   latest  7d ago

 

The oc new-app command can be used to create a new app from the image on Docker Hub.

~]$ oc new-app --image hello-world
--> Found container image feb5d9f (3 months old) from Docker Hub for "hello-world"

    * An image stream tag will be created as "hello-world:latest" that will track this image

--> Creating resources ...
    imagestream.image.openshift.io "hello-world" created
    deployment.apps "hello-world" created
--> Success
    Run 'oc status' to view your app

 

The --as-deployment-config flag can be used to create the deployment as a deployment config instead of a regular "deployment".

oc new-app --image hello-world --as-deployment-config

 

Since a simple search with something like "hello-world" or "nginx" will return more than one possible match, you'll typically want to include the name of the repository that you are pulling the image from. For example, on Docker Hub, I have an image in my repository called hello-world.

 

In this scenario, I would issue the following command.

oc new-app --image jeremycanfield/hello-world:latest

 

Or, you could create a JSON file such as cakephp.json that contains the JSON needed to deploy the app and then use the oc create command with the -f or --filename option to deploy the app.

oc create --filename hello-world.json

 

If the image was able to be pulled from Docker Hub, something like this should be returned.

~]$ oc new-app --image jeremycanfield/hello-world:latest --as-deployment-config
--> Found container image e288984 (2 days old) from Docker Hub for "jeremycanfield/hello-world:latest"

    * An image stream tag will be created as "hello-world:latest" that will track this image
    * This image will be deployed in deployment config "hello-world"
    * Port 8080/tcp will be load balanced by service "hello-world"
      * Other containers can access this service through the hostname "hello-world"

--> Creating resources ...
    imagestream.image.openshift.io "hello-world" created
    deploymentconfig.apps.openshift.io "hello-world" created
    service "hello-world" created
--> Success

 

There should now be an image stream for the deployment in your currently selected namespace.

~]# oc get imagestreams
NAME          DOCKER REPO                                                        TAGS      UPDATED
hello-world   image-registry.openshift-image-registry.svc:5000/foo/hello-world   latest   2 minutes ago

 

The oc get deployments or oc get deploymentconfigs command should list the deployment.

~]$ oc get deployments
NAME          READY   UP-TO-DATE   AVAILABLE   AGE
hello-world   1/1     1            1           38s

 

The oc get pods can be used to determine if the pod was spun up from the deployment.

~]$ oc get pods
NAME                           READY   STATUS    RESTARTS   AGE
hello-world-7cd56b8d67-kwj6d   1/1     Running   0          109s

 

If the image exposes a port (see expose port in Dockerfile), the oc get services command should include an exposed service.

~]$ oc get services
NAME                                   TYPE        CLUSTER-IP       EXTERNAL-IP    PORT(S)                      AGE
hello-world                            ClusterIP   172.30.242.65    <none>         8080/TCP                     10m

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 442248 in the box below so that we can be sure you are a human.