This topic tells you how to build a Kubernetes application from a Dockerfile on Tanzu Platform.
Before you begin
Before you can deploy an app in a Space, you must:
-
Install Tanzu CLI v1.5.1 or later. See Installing the Tanzu CLI.
-
Install the latest version of the Tanzu CLI
app-developer
plug-in group:- If the
app-developer
plug-in group is already installed, verify that you’re using the latest version of the build plug-in by running:
tanzu plugin upgrade build
- If the
app-developer
plug-in group is not present, install it by running:
tanzu plugin install --group vmware-tanzu/app-developer
- If the
-
Log in to Tanzu Platform using the Tanzu CLI:
tanzu login
Initialize a ContainerApp
Before you build your application, your must initialize a ContainerApp for it. The ContainerApp defines the default build and runtime configuration for your application and is used as an input to tanzu build
. For more information about ContainerApps, see What is a ContainerApp.
To initialize a ContainerApp:
-
Navigate to the root of your source code:
cd YOUR-REPO-LOCATION
-
Initialize the ContainerApp by running:
tanzu app init
Accept the suggested defaults by pressing Enter.
-
From your source code repository, open file
.tanzu/config/YOUR-APPLICATION-NAME.yml
. Replacebuildpacks: {}
fromspec.build
withdockerfile: {}
as shown in the following example:spec: build: dockerfile: {} path: ../..
In this example,
path: ../..
denotes the relative location of the directory that serves as the workspace for the build from the ContainerApp YAML file.../..
is the root of the repository. -
(Optional) If your Dockerfile has a name other than
Dockerfile
or is not in the root of the build workspace, you can use thespec.build.dockerfile.path
field to provide the path to the Dockerfile relative to the build workspace root.The following example searches for a Dockerfile named
Dockerfile.test
in a directory calledsub-directory
, which is at the root of the Project:spec: build: dockerfile: path: sub-directory/Dockerfile.test path: ../..
-
(Optional) If you have a multi-stage Dockerfile where you only want a single stage to run, use the
spec.build.dockerfile.multiStageTarget
field to specify the name of the target to build. You can use this in conjunction with thepath
field.The following example builds stage
foo
in the Dockerfile calledDockerfile
, which is at the root of the Project:spec: build: dockerfile: multiStageTarget: foo path: ../..
For more information about multi-stage Dockerfiles, see the Docker documentation.
-
To deploy your app, follow the procedure in Deploy your application.
Content feedback and comments