Difficulty: beginner
Estimated Time: 30 minutes


This scenario will cover how to deploy an application from an existing container image using oc in the command line for OpenShift.

In this scenario a sample application https://hub.docker.com/r/openshiftkatacoda/blog-django-py from Docker Hub is used.

This image is a sample implementation of a blog application, designed to show off various features of OpenShift.

The blog application is implemented using Python and Django.

Attention: You can executed the oc statements by clicking on the statement in the step description. Steps marked as mandatory has to be excuted to fullfill the scenario.

Hint: You can use the OpenShift Cluster as playground for OpenShift as well. There is no need to follow the steps.

Deploying an Application from an external Image in OpenShift with Cli

Step 1 of 5

Preparing the OpenShift cluster

Objective of this step

Create a project myproject under the user developer for futher use in the szenario.

Step One

When the OpenShift environment is created you will be logged in initially as a cluster admin on the command line. This will allow you to perform operations which would normally be performed by a cluster admin.

See the current user in the OpenShift Cluster:

oc whoami

Before creating any applications, it is recommended you login as a distinct user. This will be required if you want to log in to the web console and use it. Check

To login to the OpenShift cluster from the Terminal run:

oc login -u developer -p developer [[HOST_SUBDOMAIN]]-8443-[[KATACODA_HOST]].environments.katacoda.com mandatory

This will log you in using the credentials:

Username: developer
Password: developer

Use the same credentials to log into the web console.

Now your have changed to the User developer:

oc whoami

In order that you can still run commands from the command line as a cluster admin, the sudoer role has been enabled for the developer account. To execute a command as a cluster admin use the --as system:admin option to the command. For example:

oc get projects --as system:admin

In contrats the developer user has no resources defined yet:

oc get projects

Creating your own Project

To create a new project called myproject run the command:

oc new-project myproject mandatory

You could instead create the project from the web console. If you do this, to change to the project from the command line run the command:

oc project myproject

Persistent Volume Claims

Persistent volumes have been pre-created in the scenario environment. These will be used if you make persistent volume claims for an application. The volume sizes are defined as 100Gi each, however you are limited by how much disk space the host running the OpenShift environment has, which is much less.

To view the list of available persistent volumes you can run:

oc get pv --as system:admin

Builder Images and Templates

The scenario environment is pre-loaded with Source-to-Image (S2I) builders for Java (Wildfly), Javascript (Node.JS), Perl, PHP, Python and Ruby. Templates are also available for MariaDB, MongoDB, MySQL, PostgreSQL and Redis.

You can see the list of what is available, and what versions, under Add to Project in the web console, or by running from the command line:

oc new-app -L

Running Images as a Defined User

By default OpenShift prohibits images from running as the root user or as a specified user. Instead, each project is assigned its own unique range of user IDs that application images have to run as.

If you attempt to run an arbitrary image from an external image registry such a Docker Hub, which is not built to best practices, or requires that it be run as root, it may not work as a result.

In order to run such an image, you will need to grant additional privileges to the project you create to allow it to run an application image as any user ID. This can be done by running the command:

oc adm policy add-scc-to-user anyuid -z default -n myproject --as system:admin mandatory