$ oc new-app .
You can create a new OpenShift application using the
web console or
by running the oc new-app
command from the CLI. OpenShift
creates a new application by specifying source
code, images, or
templates. The new-app
command looks for images
on the local Docker installation (if available), in a
Docker
registry, or an OpenShift
image
stream.
If you specify source code, new-app
attempts to construct a
build configuration that builds your
source into a new application
image.
It also constructs a
deployment
configuration that deploys that new image, and a
service to
provide load balanced access to the deployment that is running your image.
If you specify source code, you may need to
run a build with |
You can create a new application using the oc new-app
command from
the CLI.
The new-app
command allows you to create applications using source code from a
local or remote Git repository. If only a source repository is specified,
new-app
tries to automatically determine the
type of
build
strategy to use (Docker
or Source
), and in the case of Source
type
builds, an appropriate language builder image.
You can tell new-app
to use a subdirectory of your source code repository by
specifying a --context-dir
flag. Also, when specifying a remote URL, you can
specify a Git reference to use by appending #[reference]
to the end of the
URL.
If using a local Git repository, the repository must have an origin remote that points to a URL accessible by the OpenShift cluster. |
$ oc new-app .
$ oc new-app https://github.com/openshift/sti-ruby.git \ --context-dir=2.0/test/puma-test-app
$ oc new-app https://github.com/openshift/ruby-hello-world.git#beta4
If new-app
finds a Dockerfile in the repository, it generates a
Docker
build strategy. Otherwise, it generates a
Source
strategy. To use a specific strategy, set the --strategy
flag to either
source
or docker
.
new-app
to Use the Docker
Strategy for a Local Source Repository:$ oc new-app /home/user/code/myapp --strategy=docker
If creating a Source
build, new-app
attempts to determine which language
builder to use based on the presence of certain files in the root of the
repository:
Language | Files |
---|---|
|
Rakefile, Gemfile, config.ru |
|
pom.xml |
|
app.json, package.json |
|
index.php, composer.json |
|
requirements.txt, config.py |
|
index.pl, cpanfile |
After a language is detected, new-app
searches the OpenShift server for
image
stream tags that have a supports
annotation matching the detected language,
or an image stream that matches the name of the detected language. If a match is
not found, new-app
searches the Docker Hub
registry for an image that matches the detected language based on name.
To override the image that new-app
uses as the builder for a particular source
repository, the image (either an image stream or Docker specification) can be
specified along with the repository using a ~
as a separator.
$ oc new-app myproject/my-ruby~https://github.com/openshift/ruby-hello-world.git
$ oc new-app openshift/ruby-20-centos7:latest~/home/user/code/my-ruby-app
The new-app
command generates the necessary artifacts to deploy an existing
image as an application. Images can come from image streams in the OpenShift
server, images in a specific registry or Docker
Hub, or images in the local Docker server.
The new-app
command attempts to determine the type of image specified in the
arguments passed to it. However, you can explicitly tell new-app
whether the
image is a Docker image (using the --docker-image
argument) or an image stream
(using the -i|--image
argument).
If you specify an image from your local Docker repository, you must ensure that the same image is available to the OpenShift cluster nodes. |
$ oc new-app mysql
To create an application using an image in a private registry, specify the full Docker image specification.
$ oc new-app myregistry:5000/example/myimage
If the registry that the image comes from is not
secured
with SSL, cluster administrators must ensure that the Docker daemon on the
OpenShift nodes is run with the |
To create an application from an existing image stream, specify the namespace (optional), name, and tag (optional) for the image stream.
$ oc new-app my-stream:v1
The new-app
command can instantiate a template from a
previously stored template or from a template file. To instantiate a
previously stored template, specify the name of the template as an argument. For
example, store a
sample
application template and use it to create an application.
$ oc create -f examples/sample-app/application-template-stibuild.json $ oc new-app ruby-helloworld-sample
To use a template in the file system directly, without first storing it in
OpenShift, use the -f|--file
argument or simply specify the file name as the
argument to new-app
.
$ oc new-app -f examples/sample-app/application-template-stibuild.json
When creating an application based on a template, use the
-p|--param
argument to set parameter values defined by the template.
$ oc new-app ruby-helloworld-sample \ -p ADMIN_USERNAME=admin,ADMIN_PASSWORD=mypassword
When generating applications from source or an
image, you can use the -e|--env
argument to specify
environment to be passed to the application container at run time.
$ oc new-app openshift/postgresql-92-centos7 \ -e POSTGRESQL_USER=user \ -e POSTGRESQL_DATABASE=db \ -e POSTGRESQL_PASSWORD=password
When generating applications from source,
images, or templates,
you can use the l|--label
argument to add labels to objects created by
new-app
. This is recommended, as labels make it easy to collectively select,
manipulate, and delete objects associated with the application.
new-app
:$ oc new-app https://github.com/openshift/ruby-hello-world -l name=hello-world
The new-app
command generates OpenShift objects that will build, deploy, and
run the application being created. Normally, these objects are created in the
current project using names derived from the input source repositories or the
input images. However, new-app
allows you to modify this behavior.
To see a dry-run of what new-app
will create, you can use the -o|--output
flag with a value of either yaml
or json
. You can then use the output to
preview the objects that will be created, or redirect it to a file that you
can edit and then use with oc create
to create the OpenShift objects.
new-app
Artifacts to a File, Edit Them, Then Create Them Using oc create
:$ oc new-app https://github.com/openshift/ruby-hello-world -o json > myapp.json $ vi myapp.json $ oc create -f myapp.json
Objects created by new-app
are normally named after the source repository or
the image used to generate them. You can set the name of the objects produced by
adding a --name
flag to the command.
new-app
Artifacts with a Different Name:$ oc new-app https://github.com/openshift/ruby-hello-world --name=myapp
Normally new-app
creates objects in the current project. However, you can tell
it to create objects in a different project that you have access to using the
-n|--namespace
argument.
new-app
Artifacts in a Different Project:$ oc new-app https://github.com/openshift/ruby-hello-world -n myproject
The set of artifacts created by new-app
depends on the artifacts passed as
input: source repositories, images, or templates.
Artifact | Description |
---|---|
|
A |
|
For |
|
A |
|
The |
Other |
Other objects can be generated when instantiating templates. |
The new-app
command allows creating multiple applications from
source, images, or
templates at once. To do this, simply specify
multiple parameters to the new-app
call. Labels specified in the command line
apply to all objects created by the single call. Environment variables apply to
all components created from source or images.
$ oc new-app https://github.com/openshift/ruby-hello-world mysql
If a source code repository and a builder image are specified as separate
arguments, |
The new-app
command allows deploying multiple images together in a single pod.
In order to specify which images to group together, use the +
separator. The
--group
command line argument can also be used to specify which images should
be grouped together. To group the image built from a source repository with
other images, specify its builder image in the group.
$ oc new-app nginx+mysql
$ oc new-app \ ruby~https://github.com/openshift/ruby-hello-world \ mysql \ --group=ruby+mysql
You can also create applications using the web console:
While in the desired project, click Add to Project:
Enter the repository URL for the application to build:
Select either a builder image from the list of images in your project, or from the global library:
Only image stream tags which have the builder tag listed in their annotations will appear in this list, as demonstrated here: |
kind: "ImageStream" apiVersion: "v1" metadata: name: "ruby" creationTimestamp: null spec: dockerImageRepository: "registry.access.redhat.com/openshift3/ruby-20-rhel7" tags: - name: "2.0" annotations: description: "Build and run Ruby 2.0 applications" iconClass: "icon-ruby" tags: "builder,ruby" (1) supports: "ruby:2.0,ruby" version: "2.0"
1 | Including builder here ensures this ImageStreamTag will appear in the
web console as a builder. |
Modify the settings in the new application screen to configure the objects to support your application:
1 | The builder image name and description. |
2 | The application name used for the generated OpenShift objects. |
3 | Routing configuration section for making this application publicly accessible. |
4 | Deployment configuration section for customizing deployment triggers and image environment variables. |
5 | Build configuration section for customizing build triggers. |
6 | Replica scaling section for configuring the number of running instances of the application. |
7 | The labels to assign to all items generated for the application. You can add and edit labels for all objects here. |