# Static IP and tunnels in Docker

Source: https://prontaro.com/docs/integrations/docker/

Connect Docker containers to allowlisted APIs from a fixed IPv4 and accept inbound tunnels in Compose without changing host routing.

Containers inherit the host’s outbound IP — which shifts whenever a VM is replaced or scaled — and normally require published host ports for inbound access. In Docker Compose, Prontaro covers both cases with two setups: proxy environment variables for HTTP traffic, or a lightweight `prontaro` sidecar for TCP forwarding and inbound tunnels.

## Which method to choose

| Method | What it solves | Extra container needed |
| --- | --- | --- |
| **1. `PRONTARO_PROXY_URL` + `NO_PROXY`** | Outbound HTTP/HTTPS and `socks5h://` calls from your dedicated IPv4 | No |
| **2A. Sidecar `prontaro forward`** | Outbound TCP to allowlisted databases and SFTP when the driver has no SOCKS5 support | Yes (`--listen 0.0.0.0` on Compose network, or `network_mode: "service:app"`) |
| **2B. Sidecar `prontaro http` / `tcp`** | Inbound HTTPS or TCP tunnel to a container without publishing host ports | Yes (on the Compose network) |

## Prerequisites

- For static IPv4, proxy, and `prontaro forward`: Dedicated (from $12/mo, 100 GB traffic) or Pro ([plans](https://prontaro.com/docs/billing/plans.md)).
- For inbound `prontaro http`: any plan (`*.prontaro.dev` on Free, `*.prontaro.run` on paid plans); for `prontaro tcp`: Tunnels ($6/mo) or higher.
- Docker Engine and Docker Compose v2 (`docker compose`).

## Method 1. Outbound proxy (`PRONTARO_PROXY_URL` + `NO_PROXY`)

Best for backend containers calling allowlisted REST/GraphQL APIs.

### Step 1. Create proxy credentials

Add your dedicated IPv4 (`/32`) to the partner API allowlist and create proxy credentials in the dashboard. Leave the **To** destination list open until you verify the IP.

1. Open **IP addresses** in [my.prontaro.com](https://my.prontaro.com/ips) and click **Create proxy credentials**.
2. Name them `docker-app` and copy the `HTTPS` URL (port `:443`).

IP addresses Proxy credentials [Open in dashboard](https://my.prontaro.com/ips)

### Step 2. Configure `compose.yml` and exclude internal networks

Store credentials in `.env` (keep `.env` in `.gitignore` and never bake secrets into a `Dockerfile`):

```env
# .env
PRONTARO_PROXY_URL=https://u_docker:s3cr3t@<entry>.prontaro.io:443
```

If your code explicitly passes `PRONTARO_PROXY_URL` only to the external API client, no global proxy variable is needed. If an app or tool reads standard `HTTPS_PROXY` / `HTTP_PROXY`, always set `NO_PROXY` to exclude Docker Compose service names and private ranges:

```yaml
# compose.yml
services:
  app:
    build: .
    env_file: .env
    environment:
      # Preferred: pass explicitly only to external API clients
      PRONTARO_PROXY_URL: ${PRONTARO_PROXY_URL}
      # If using global proxy env vars, exclude internal services and RFC 1918:
      HTTPS_PROXY: ${PRONTARO_PROXY_URL}
      HTTP_PROXY: ${PRONTARO_PROXY_URL}
      NO_PROXY: localhost,127.0.0.1,postgres,redis,.local,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
    depends_on:
      - postgres
      - redis

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_PASSWORD: dev-only-password

  redis:
    image: redis:7-alpine
```

> **Missing NO_PROXY breaks internal Compose traffic**
>
> If internal service hostnames (`postgres`, `redis`, `api-internal`) are omitted from `NO_PROXY`, HTTP clients route internal calls to the external proxy and fail with `403`.
>
> Prontaro servers intentionally block private subnets (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, `127.0.0.0/8`).

### Step 3. Verify the outbound IP

Start the stack and check the outbound IP from inside the container before restricting allowed destinations:

```
 docker compose up -d && docker compose exec app curl -fsS --proxy "$PRONTARO_PROXY_URL"
203.0.113.10
```

### Step 4. Lock down allowed hosts and ports

After verification, restrict `docker-app` to the exact partner hosts and ports:

1. Open **IP addresses → Proxy credentials** in [my.prontaro.com](https://my.prontaro.com/ips), select `docker-app`, open the **Access** tab, and add `api.example.com:443` under **To**.
2. Save.

IP addresses Proxy credentials Access [Open in dashboard](https://my.prontaro.com/ips)

## Method 2. Sidecar container `prontaro` with `PRONTARO_KEY`

When a container needs outbound TCP port forwarding (`prontaro forward`) or an inbound tunnel (`prontaro http` / `prontaro tcp`), build a tiny sidecar image with the `prontaro` binary and authenticate it via `PRONTARO_KEY`.

### Build `Dockerfile.prontaro`

Running `install.sh` as `root` installs `prontaro` directly into `/usr/local/bin/prontaro`:

```dockerfile
# Dockerfile.prontaro
FROM alpine:3.20

RUN apk add --no-cache ca-certificates curl \
 && curl -fsSL https://prontaro.com/install.sh | sh

ENTRYPOINT ["prontaro"]
```

When `PRONTARO_KEY` is set, `prontaro` works even in read-only containers (`read_only: true`) without a writable state directory or `$HOME` (ephemeral in-memory state). If you want offline cache persistence across restarts, also mount a `/state` volume and set `PRONTARO_STATE_DIR=/state`.

Issue a dedicated CLI token in [my.prontaro.com](https://my.prontaro.com/cli) and save it in `.env` as `PRONTARO_KEY`:

1. Open the **CLI** page in [my.prontaro.com](https://my.prontaro.com/cli) and create a token named `docker-sidecar`.
2. Put it in `.env`: `PRONTARO_KEY=<token>`. `prontaro CLI` reads `PRONTARO_KEY` directly from the environment — no `prontaro login` command is needed on container startup.

CLI [Open in dashboard](https://my.prontaro.com/cli)

### Option 2A. Outbound TCP forwarding (`prontaro forward`)

By default `prontaro forward` binds to `127.0.0.1:<port>`. In Docker Compose, pass `--listen 0.0.0.0` so sibling containers on the private Compose network can reach `prontaro-forward:15432` (or attach the sidecar via `network_mode: "service:app"` to keep it on `127.0.0.1:15432`). Pass `--no-input` so the process never prompts, and configure `restart: unless-stopped` (or `--restart unless-stopped` with `docker run`): on startup refusals (such as an unpaid or blocked account), `prontaro` exits with a non-zero code instead of waiting, and Docker restarts the container automatically with backoff until it comes up:

```yaml
# compose.yml
services:
  app:
    build: .
    environment:
      DATABASE_URL: postgres://app:secret@prontaro-forward:15432/prod?sslmode=require
    depends_on:
      - prontaro-forward

  prontaro-forward:
    build:
      context: .
      dockerfile: Dockerfile.prontaro
    read_only: true
    environment:
      PRONTARO_KEY: ${PRONTARO_KEY}
    command: ["forward", "15432", "db.example.com:5432", "--listen", "0.0.0.0", "--ip", "203.0.113.10", "--no-input", "--json"]
    restart: unless-stopped
```

> **Read-only containers vs mounted /state volume**
>
> With `PRONTARO_KEY`, the sidecar runs cleanly with `read_only: true` and no volume. If you also want `prontaro` to cache local state and forwarding credentials across restarts when the Prontaro API is temporarily unreachable, mount a named volume at `/state` and set `PRONTARO_STATE_DIR=/state`.

### Option 2B. Inbound tunnels (`prontaro http` and `prontaro tcp`)

For inbound traffic, run the sidecar on the normal Compose bridge network and target sibling containers by service name (`app:3000` or `postgres:5432`). Keep `--no-input` paired with `restart: unless-stopped` (or `--restart unless-stopped` in `docker run`) so Docker retries startup refusals automatically (once running, tunnels wait and recover on their own):

```yaml
# compose.yml
services:
  app:
    build: .
    # No host ports need to be published

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}

  prontaro-http:
    build:
      context: .
      dockerfile: Dockerfile.prontaro
    environment:
      PRONTARO_KEY: ${PRONTARO_KEY}
      PRONTARO_STATE_DIR: /state
    volumes:
      - prontaro_http_state:/state
    command: ["http", "app:3000", "--name", "staging-web", "--no-input", "--json"]
    restart: unless-stopped

  prontaro-tcp:
    build:
      context: .
      dockerfile: Dockerfile.prontaro
    environment:
      PRONTARO_KEY: ${PRONTARO_KEY}
      PRONTARO_STATE_DIR: /state
    volumes:
      - prontaro_tcp_state:/state
    command: ["tcp", "postgres:5432", "--name", "staging-pg", "--to", "203.0.113.10", "--no-input", "--json"]
    restart: unless-stopped

volumes:
  prontaro_http_state:
  prontaro_tcp_state:
```

New TCP tunnels start closed to everyone — after starting the container, open [access](https://prontaro.com/docs/tunnels/access.md) only to trusted IPs:

#### In the dashboard

1. Open **Tunnels** in [my.prontaro.com](https://my.prontaro.com/), select `staging-pg`, and switch to the **Access** tab.
2. Add the allowed IPv4 address or CIDR and click **Save**.

Tunnels Access [Open in dashboard](https://my.prontaro.com/tunnels)

#### In the terminal (CLI)

```bash
docker compose exec prontaro-tcp prontaro access staging-pg allow 198.51.100.7
```

## Docker notes and limits

- **Never bake secrets into images:** pass `PRONTARO_PROXY_URL` and `PRONTARO_KEY` via runtime `env_file` or Docker Secrets, never `Dockerfile` `ENV` or `ARG`.
- **Use `--json` for logs:** pass `--json` to sidecar commands (`forward`, `http`, `tcp`) so Docker log drivers and log aggregators receive structured JSON lines.
- **One state volume per sidecar:** if you run both `prontaro-http` and `prontaro-tcp`, give each sidecar its own `/state` volume.
- **Choose a nearby IP location:** pick the Prontaro location in the dashboard closest to your hosts and target APIs.

## Common errors

| Symptom | Cause | Fix |
| --- | --- | --- |
| `403 destination_denied` when calling `postgres` or `redis` | Internal container hostnames are missing from `NO_PROXY`. | Add service names and `10.0.0.0/8,172.16.0.0/12,192.168.0.0/16` to `NO_PROXY`. |
| `Connection refused` on `prontaro-forward:15432` from `app` | `prontaro forward` is listening on `127.0.0.1` instead of `0.0.0.0`, or not sharing `app`’s network namespace. | Pass `--listen 0.0.0.0` (on a private Compose network) or set `network_mode: "service:app"`. |
| `407 Proxy Authentication Required` | Wrong password in `.env`, or newly created credentials are still propagating. | Copy the exact URL under [IP addresses](https://my.prontaro.com/ips), update `.env`, and run `docker compose up -d`. |
| `You have 2 addresses — choose which one` | Pro account has multiple IPs and `--ip` was omitted. | Pass `--ip <your-IP>` in the sidecar `command:`. |

## Next steps

- [PostgreSQL and AWS RDS with a static IP](https://prontaro.com/docs/integrations/postgres.md) — connect to allowlisted cloud databases over `prontaro forward` or `socks5h://` and expose private databases.
- [Static IP for Fly.io](https://prontaro.com/docs/integrations/fly-io.md) — configure outbound proxies and `prontaro forward` in Fly.io container apps.
- [Local port forwarding (`prontaro forward`)](https://prontaro.com/docs/outbound/forward.md) — full reference for outbound TCP forwarding to databases and SFTP servers.
- [TCP tunnels](https://prontaro.com/docs/tunnels/tcp.md) — accept inbound TCP connections on your dedicated IPv4 with IP allowlists.
