Skip to main content
Version: v3

odo init

The odo init command is the first command to be executed when you want to bootstrap a new component, using odo. If sources already exist, the command odo dev should be considered instead.

This command must be executed from a directory with no devfile.yaml file.

The command can be executed in two flavors, either interactive or non-interactive.

Running the command

Interactive mode

In interactive mode, the behavior of odo init depends on whether the current directory already contains source code or not.

Empty directory

If the directory is empty, you will be guided to:

  • choose a devfile from the list of devfiles present in the registry or registries referenced (using the odo registry command),
  • configure the devfile
  • choose a starter project referenced by the selected devfile,
  • choose a name for the component present in the devfile; this name must follow the Kubernetes naming convention and not be all-numeric.
odo init
Example
$ odo init
__
/ \__ Initializing a new component
\__/ \ Files: No source code detected, a starter project will be created in the current directory
/ \__/ odo version: v3.15.0
\__/

Interactive mode enabled, please answer the following questions:
? Select architectures to filter by: [Use arrows to move, space to select, <right> to all, <left> to none, type to filter]
> [x] amd64
[ ] arm64
[ ] ppc64le
[ ] s390x
? Select architectures to filter by: amd64
? Select language: Java
? Select project type: Maven Java
? Select version: 1.2.0
✓ Downloading devfile "java-maven:1.2.0" from registry "DefaultDevfileRegistry" [4s]

↪ Container Configuration "tools":
OPEN PORTS:
- 8080
- 5858
ENVIRONMENT VARIABLES:
- DEBUG_PORT = 5858

? Select container for which you want to change configuration? NONE - configuration is correct
? Which starter project do you want to use? springbootproject
? Enter component name: my-java-maven-app
✓ Downloading starter project "springbootproject" [1s]

You can automate this command by executing:
odo init --name my-java-maven-app --devfile java-maven --devfile-registry DefaultDevfileRegistry --devfile-version 1.2.0 --starter springbootproject

Your new component 'my-java-maven-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

Directory with sources

If the current directory is not empty, odo init will make its best to autodetect the type of application and propose you a Devfile that should suit your project. It will try to detect the following, based on the files in the current directory:

  • Language
  • Project Type
  • Ports used in your application
  • A Devfile that should help you start with odo

If the information detected does not seem correct to you, you are able to select a different Devfile.

In all cases, you will be guided to:

  • configure the devfile
  • choose a name for the component present in the devfile; this name must follow the Kubernetes naming convention and not be all-numeric.
odo init
Example
$ odo init
__
/ \__ Initializing a new component
\__/ \ Files: Source code detected, a Devfile will be determined based upon source code autodetection
/ \__/ odo version: v3.15.0
\__/

Interactive mode enabled, please answer the following questions:
✓ Determining a Devfile for the current directory [1s]
Based on the files in the current directory odo detected
Supported architectures: all
Language: JavaScript
Project type: Node.js
Application ports: 8080
The devfile "nodejs:2.1.1" from the registry "DefaultDevfileRegistry" will be downloaded.
? Is this correct? Yes
✓ Downloading devfile "nodejs:2.1.1" from registry "DefaultDevfileRegistry" [3s]

↪ Container Configuration "runtime":
OPEN PORTS:
- 8080
- 5858
ENVIRONMENT VARIABLES:
- DEBUG_PORT = 5858

? Select container for which you want to change configuration? NONE - configuration is correct
? Enter component name: node-echo

You can automate this command by executing:
odo init --name node-echo --devfile nodejs --devfile-registry DefaultDevfileRegistry --devfile-version 2.1.1

Your new component 'node-echo' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

Non-interactive mode

In non-interactive mode, you will have to specify from the command-line the information needed to get a devfile.

If you want to download a devfile from a registry, you must specify the devfile name with the --devfile flag. The devfile with the specified name will be searched in the registries referenced (using odo preference view), and the first one matching will be downloaded. If you want to download the devfile from a specific registry in the list or referenced registries, you can use the --devfile-registry flag to specify the name of this registry. By default, odo uses the official devfile registry registry.devfile.io. You can use the registry web interface to view its content. If you want to download a specific version of a devfile, you can specify the version with the --devfile-version flag.

If you prefer to download a devfile from a URL or from the local filesystem, you can use the --devfile-path instead.

The --starter flag indicates the name of the starter project (as referenced in the selected devfile), that you want to use to start your development. To see the available starter projects for devfile stacks in the official devfile registry use its web interface to view its content.

The required --name flag indicates how the component initialized by this command should be named. The name must follow the Kubernetes naming convention and not be all-numeric.

If you know what ports your application uses, you can specify the --run-port flag to initialize the Devfile with the specified ports, instead of the default ones set in the registry. The --run-port flag is a repeatable flag that will make odo read the downloaded Devfile and look for the container component referenced by the default run command. It will then overwrite the container component endpoints with the ports specified. As such, it requires the default run command to be an exec command pointing to a container component.

Fetch Devfile from any registry of the list

In this example, the devfile will be downloaded from the StagingRegistry registry, which is the first one in the list containing the nodejs-react devfile.

odo init --name <component-name> --devfile <devfile> [--starter STARTER]
Example
$ odo preference view
[...]

Devfile registries:
NAME URL SECURE
StagingRegistry https://registry.stage.devfile.io No
DefaultDevfileRegistry https://registry.stage.devfile.io No
$ odo registry --devfile nodejs-react
NAME REGISTRY DESCRIPTION ARCHITECTURES VERSIONS
nodejs-react StagingRegistry React is a free and open-source front-en... 2.0.2, 2.2.0
nodejs-react DefaultDevfileRegistry React is a free and open-source front-en... 2.0.2, 2.2.0
$ odo init --devfile nodejs-react --name my-nr-app
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.15.0
\__/

✓ Downloading devfile "nodejs-react" [3s]

Your new component 'my-nr-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

Fetch Devfile from a specific registry of the list

In this example, the devfile will be downloaded from the DefaultDevfileRegistry registry, as explicitly indicated by the --devfile-registry flag.

Example
$ odo preference view
[...]

Devfile registries:
NAME URL SECURE
StagingRegistry https://registry.stage.devfile.io No
DefaultDevfileRegistry https://registry.stage.devfile.io No
$ odo init --name my-spring-app --devfile java-springboot --devfile-registry DefaultDevfileRegistry --starter springbootproject
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.15.0
\__/

✓ Downloading devfile "java-springboot" from registry "DefaultDevfileRegistry" [4s]
✓ Downloading starter project "springbootproject" [874ms]

Your new component 'my-spring-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

Fetch Devfile from a URL

odo init --devfile-path <URL> --name <component-name> [--starter STARTER]
Example
$ odo init --devfile-path https://registry.stage.devfile.io/devfiles/nodejs-angular --name my-nodejs-app --starter nodejs-angular-starter
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.15.0
\__/

✓ Downloading devfile from "https://registry.stage.devfile.io/devfiles/nodejs-angular" [1s]
✓ Downloading starter project "nodejs-angular-starter" [958ms]

Your new component 'my-nodejs-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

Fetch Devfile of a specific version

odo init --devfile <devfile-name> --devfile-version <devfile-version> --name <component-name> [--starter STARTER]
Examples
$ odo init --devfile go --name my-go-app --devfile-version 2.2.0
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.15.0
\__/

✓ Downloading devfile "go:2.2.0" [3s]

Your new component 'my-go-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.
To deploy your component to a cluster use "odo deploy".
note

Use "latest" as the version name to fetch the latest version of a given Devfile.

Example
$ odo init --devfile go --name my-go-app --devfile-version latest
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.15.0
\__/

✓ Downloading devfile "go:latest" [4s]

Your new component 'my-go-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.
To deploy your component to a cluster use "odo deploy".

Specify the application ports

odo init \
--devfile <devfile-name> \
--name <component-name> \
--run-port <port> [--run-port ANOTHER_PORT] \
[--starter STARTER]

In this example, odo will download the Devfile from the registry and overwrite the container endpoints with the ones specified in --run-port. This works because the Devfile downloaded from the registry defines a default run command of type exec and referencing a container component.

Example
$ odo init --devfile go --name my-go-app --run-port 3456 --run-port 9876
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.15.0
\__/

✓ Downloading devfile "go" [48ms]

Your new component 'my-go-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.