Skip to main content

How to Expose Multiple Ports in Kamal Accessories

2 min read

If you've been working with Kamal accessories, you might have noticed that the official documentation only mentions the port option for exposing a single port. But what if your accessory needs multiple ports exposed?

Good news: Kamal already supports this through the --publish option, even though it's not prominently documented.

The Standard Approach

The documented way to expose a port looks like this:

accessories:
  redis:
    image: redis:latest
    port: 6379

This works great for simple cases, but many applications need multiple ports exposed.

Publishing Multiple Ports

Instead of using port, you can use the publish option under options to expose as many ports as you need:

accessories:
  questdb:
    image: questdb/questdb:7.3
    options:
      publish:
        - "9000:9000"
        - "9003:9003"
        - "9009:9009"
        - "8812:8812"

In this example, QuestDB requires four different ports:
- 9000: REST API and Web Console
- 9003: Min health server
- 9009: InfluxDB line protocol
- 8812: Postgres wire protocol

Why This Matters

Many production-grade accessories require multiple ports for different protocols or services:
- Databases with separate ports for different wire protocols
- Monitoring tools with data ingestion and query interfaces
- Message queues with management UIs and messaging ports

Being able to publish multiple ports means you can deploy these complex accessories without workarounds or custom Docker configurations.

The Format

Each entry in the publish array follows Docker's standard port mapping format:

"host_port:container_port"

You can also use the extended format if you need to specify the protocol:
yaml
publish:
- "9000:9000/tcp"
- "8125:8125/udp"

Try It Out

This feature works right now in Kamal without any special configuration. If you've been holding back on deploying certain accessories because of port limitations, give the publish option a try.

Have you discovered other undocumented Kamal features? The community would love to hear about them!