How do I connect to pods in a preview environment using Porter?

Last updated: February 9, 2026

Context

When working with Porter, developers often need to connect to pods in different environments, including preview environments. While connecting to production pods is commonly done using the `porter app run` command, connecting to preview environment pods requires a slightly different syntax.

Answer

To connect to pods in a preview environment using Porter, use the following command syntax:

porter app run -x <preview-branch-name> <app-name> -- bash

For example, if you have a preview environment for a branch called feature-123 and want to connect to an app called backend-service, you would run:

porter app run -x feature-123 backend-service -- bash

Further Use Cases:

The same -x flag syntax can be used for other operations in preview environments. For example, to retrieve environment variables from a preview environment pod:

porter app run -x <preview-branch-name> <app-name> -- env | grep PORTER_DOMAINS

You can use the -e flag to connect to existing running pods for inspecting their state or accessing runtime files.

porter app run -e -x <preview-branch-name> <app-name> -- env | grep PORTER_DOMAINS

You can also set environment variables in preview environments using:

porter env set -x <preview-branch-name> -a <app-name> VARIABLE_NAME=value

It's essential to understand the different flags and their implications on container behavior:

  • Use -x <branch-name> for preview environments, which creates ephemeral containers.

  • Use -e to connect directly to existing running containers/pods.

  • Use neither flag to create ephemeral containers in the current environment.

In summary, Porter provides flexible connection options:

  • -x for preview environments

  • -e for existing pods

This allows for efficient management and debugging across different environments and container states.