Hako
How-to Guides

How to Set Up Docker Compose Mode

Configure Docker Compose to manage isolated environments per branch with hako.

This guide shows how to configure a project using Docker Compose so hako can manage isolated environments with deterministic ports for every branch.

Assumptions

  • Project contains a docker-compose.yml or compose.yml file.
  • Docker and Docker Compose are installed and running.
  • You are familiar with basic hako commands.

Steps

  1. Replace hardcoded ports with variables Edit your docker-compose.yml to use the PORT variable assigned by hako.

    services:
      web:
        ports:
          - "${PORT:-3000}:3000"
  2. Inject hako environment variables Add .env.hako to the env_file list for services that require port variables or other hako-managed metadata.

    services:
      web:
        env_file:
          - .env.hako
  3. Initialize the environment Run the following command to create a new worktree and start the services. Hako auto-detects the compose file and generates a hako.yml configuration.

    hako new feature-branch --start
  4. Verify assigned ports Check the ports assigned to the new environment.

    hako ports feature-branch

Troubleshooting

If auto-detection fails to identify your port variables, manually add them to the ports list in hako.yml.

See the configuration reference for all available options.

See also

ops.origin: Masakiro Corp.

On this page