Skip to main content
porter apply is the primary command for deploying applications using configuration-as-code. It reads a porter.yaml file, builds a new container image, and deploys your application to the cluster. By default, porter apply performs a full build and deploy cycle. Use --no-build to skip building and deploy with an existing image. You can also pass environment variables and secrets directly via command-line flags (--variables, --secrets) without modifying your porter.yaml.
This command is the recommended way to deploy applications in CI/CD pipelines and for version-controlled infrastructure.

Usage

porter apply -f porter.yaml [flags]

Prerequisites

Options

Required Flags

FlagShortDescription
--file-fPath to the porter.yaml configuration file

Deployment Options

FlagShortDescription
--appOverride the app name specified in porter.yaml
--target-xSpecify a deployment target (name or ID)
--wait-wWait for the deployment to complete before exiting
--preview-pDeploy to a preview environment based on current git branch

Build Options

FlagDescription
--no-buildSkip building a new image and deploy with an existing image
--no-pullDon’t pull the previous image before building
--tagSpecify a custom image tag (overrides value in porter.yaml)
--image-repositorySet the image repository to use
--build-contextOverride the build context directory
--build-methodSet build method: docker or pack
--dockerfileOverride the Dockerfile path (for docker builds)
--builderSet the builder to use (for pack builds)
--attach-buildpacksAttach buildpacks to use (for pack builds)
--remoteBuild remotely using kpack in the cluster instead of locally (experimental)
--verboseShow verbose output during build

Environment Options

FlagDescription
--variablesSet environment variables as key=value pairs (overrides porter.yaml)
--secretsSet secrets as key=value pairs (overrides porter.yaml)

Validation Options

FlagDescription
--validateValidate the porter.yaml file without deploying
--dry-runPerform server-side validation without applying changes
--exactDisable config merging with existing app configuration

Advanced Options

FlagShortDescription
--predeployRun the predeploy job before deploying services
--helm-overrides-file-vPath to a file containing Helm value overrides
--attach-env-groupsComma-separated list of environment groups to attach

Environment Variables

You can also configure porter apply using environment variables:
VariableDescription
PORTER_APP_NAMEOverride the app name (alternative to --app)
PORTER_PROJECTTarget project ID
PORTER_CLUSTERTarget cluster ID
PORTER_TOKENAuthentication token

Examples

# Deploy using porter.yaml in the current directory
porter apply -f porter.yaml

Workflow

When you run porter apply, the following steps occur:
1

Parse Configuration

Porter reads and validates your porter.yaml file
2

Build Image

Porter builds and pushes a new container image (unless --no-build is specified)
3

Run Predeploy (if enabled)

If --predeploy is specified or predeploy is defined in porter.yaml, the predeploy job runs first
4

Deploy Services

Porter deploys or updates all services defined in the configuration
5

Wait for Rollout (if --wait)

If --wait is specified, Porter waits for all services to become healthy

Configuration File

The porter apply command expects a porter.yaml file. For detailed documentation on all available configuration options, see the porter.yaml Reference.

Minimal Example

version: v2
name: my-app

services:
  - name: web
    type: web
    run: npm start
    port: 3000
    cpuCores: 0.5
    ramMegabytes: 512

CI/CD Integration

For CI/CD pipelines, use environment variables for authentication and the --wait flag to ensure deployments complete before the pipeline continues.

GitHub Actions Example

- name: Deploy to Porter
  env:
    PORTER_TOKEN: ${{ secrets.PORTER_TOKEN }}
    PORTER_PROJECT: ${{ secrets.PORTER_PROJECT }}
    PORTER_CLUSTER: ${{ secrets.PORTER_CLUSTER }}
  run: porter apply -f porter.yaml

GitLab CI Example

deploy:
  script:
    - porter apply -f porter.yaml
  variables:
    PORTER_TOKEN: $PORTER_TOKEN
    PORTER_PROJECT: $PORTER_PROJECT
    PORTER_CLUSTER: $PORTER_CLUSTER

Troubleshooting

If your deployment fails, check the following common issues:
  • Ensure your porter.yaml is valid by running porter apply -f porter.yaml --validate
  • Verify you’re authenticated with porter auth login
  • Check that your project and cluster are correctly configured with porter config

Validation Errors

Run with --validate to check your configuration:
porter apply -f porter.yaml --validate

Dry Run

Use --dry-run for server-side validation without making changes:
porter apply -f porter.yaml --dry-run