Tanzu Platform Self-Managed 10.1

Build an application from a Dockerfile

Last Updated March 03, 2025

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.3 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:v1.1
    
  • 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:

  1. Go to the root of your source code:

    cd YOUR-REPO-LOCATION
    
  2. Initialize the ContainerApp by running:

    tanzu app init APP-NAME --build-type dockerfile
    

    Answer the prompts.

  3. (Optional) If your Dockerfile has a name other than Dockerfile or is not in the root of the build workspace, you can provide its path relative to the build workspace root by running:

    tanzu app config build dockerfile set path=PATH-TO-DOCKERFILE
    

    For example:

    $ tanzu app config build dockerfile set path=sub-directory/Dockerfile.test
    
    Updated build type: dockerfile
    

    The example searches for a Dockerfile named Dockerfile.test in a directory called sub-directory, which is at the root of the Project.

  4. (Optional) If you have a multi-stage Dockerfile where you only want a single stage to run, you can specify the name of the stage to build by running:

    tanzu app config build dockerfile set stage=DOCKERFILE-STAGE
    

    For example:

    tanzu app config build dockerfile set stage=app-building-stage
    
    Updated build type: dockerfile
    

    The example builds the stage app-building-stage in the Dockerfile you configured. The default Dockerfile is Dockerfile.

    You can configure the stage field in conjunction with the path field for your Dockerfile. For more information about multi-stage Dockerfiles, see the Docker documentation.

  5. To deploy your app, follow the procedure in Deploy your application.