Skip to content

devlanes is in beta and not ready for production use.Report an issue

Give each lane its own container

Use this when a branch needs its own version of a database, or runs migrations that would break the other lanes: each lane gets a container and a volume of its own.

::example{slug="infra-postgres-per-lane"}

The image creates the database POSTGRES_DB names, and each lane has a pgdata volume of its own.

docker-compose.yml
services:
postgres:
image: postgres:17.11-alpine
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: myapp
ports: ["127.0.0.1::5432"]
volumes: [pgdata:/var/lib/postgresql/data]
healthcheck:
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U postgres -d myapp"]
interval: 2s
retries: 30
volumes:
pgdata:

A service under infra.per_lane runs once for each lane, on a port from that lane’s block of ports. The URL reads that port, so it differs in each lane. This needs Compose 2.24.4 or newer.

devlanes.yaml
infra:
compose: docker-compose.yml
per_lane: [postgres]
global_env:
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:${{ infra.postgres.port }}/myapp

A plain docker compose in a setup entry reaches the shared containers. To run a command in the lane’s own container, name its Compose project with -p "$DEVLANES_COMPOSE_LANE_PROJECT".

Each start brings up the lane’s container. Stopping the lane leaves the container running; cleaning the lane removes the container and its volume, so its data is gone.

Terminal window
$ devlanes start
$ devlanes lane clean 1 --yes

A start into a running lane does not recreate a container you removed, for example to use a newly pulled image. Bring it back in the lane’s worktree:

Terminal window
$ devlanes infra up

Set infra.containers.<name>.per_lane, as in Run containers without Compose.