# CLI: Serverless Containers

Deploy and manage serverless containers using the DanubeData CLI.

## Prerequisites

- [DanubeData CLI installed](https://docs.danubedata.ro/cli-overview)
- Authenticated via `danube login` or `DANUBE_TOKEN`

## Quick start

Deploy a serverless container from a Docker image:

```bash
danube rapids create --name my-api --type docker_image --image node --tag 20-alpine --port 3000
```

Or deploy from a local directory:

```bash
danube rapids create --name my-api --type zip_upload --source-type dockerfile
danube rapids deploy my-api --dir ./
```

## Listing containers

```bash
danube rapids ls
```

Shows all containers with name, status, resource profile, URL, and creation date.

## Creating a container

```bash
danube rapids create
```

Without flags, the CLI guides you through interactive prompts. You can also pass flags for non-interactive creation.

### From a Docker image

```bash
danube rapids create \
  --name my-api \
  --type docker_image \
  --image node \
  --tag 20-alpine \
  --profile small \
  --port 3000
```

### From a Git repository

```bash
danube rapids create \
  --name my-api \
  --type git_repository \
  --repo https://github.com/username/my-api \
  --source-type dockerfile \
  --profile small \
  --port 8080
```

Build methods:
- `dockerfile` — Uses your project's Dockerfile
- `buildpack` — Auto-detects runtime (Node.js, Python, Go, Java, Ruby, PHP, .NET, Rust)

### From a local directory (ZIP upload)

```bash
danube rapids create \
  --name my-api \
  --type zip_upload \
  --source-type buildpack \
  --profile small \
  --port 3000
```

Then deploy your code:

```bash
danube rapids deploy my-api --dir ./
```

### Resource profiles

| Profile | vCPU | Memory |
|---------|------|--------|
| `free` | 0.01-0.1 | 64-128 MB |
| `micro` | 0.1-1 | 256-512 MB |
| `small` | 0.5-1 | 256-512 MB |
| `medium` | 1-2 | 512 MB-1 GB |
| `large` | 2-4 | 1-2 GB |

Billing is pay-per-use, with a free tier of 2 million requests per month.

## Deploying code

Deploy from a local directory to an existing container:

```bash
danube rapids deploy my-api
```

Deploy a specific directory:

```bash
danube rapids deploy my-api --dir ./app
```

Deploy without waiting for the build to complete:

```bash
danube rapids deploy my-api --no-wait
```

The CLI packages your files into a ZIP, uploads them, and polls the build status every 2 seconds (timeout: 10 minutes).

### Container resolution

You can reference containers by name, slug, ID, or ID prefix:

```bash
danube rapids deploy my-api          # by name
danube rapids deploy 42              # by ID
danube rapids deploy a1b2            # by ID prefix
```

## Viewing container details

```bash
danube rapids show my-api
```

Displays:
- ID, status, and deployment type
- Image and port
- Resource profile and monthly cost
- Scaling configuration (min/max replicas, metric, targets)
- Environment variables (values masked)

## Updating a container

Update any configuration without redeploying:

```bash
# Change resource profile
danube rapids update my-api --profile medium

# Update scaling
danube rapids update my-api --min-scale 1 --max-scale 20

# Change scaling metric
danube rapids update my-api --scaling-metric concurrency --concurrency-target 50

# Set request timeout (max 3600 seconds)
danube rapids update my-api --timeout 300

# Update Docker image
danube rapids update my-api --image node --tag 22-alpine

# Add/update environment variables
danube rapids update my-api --env DATABASE_URL=postgres://... --env API_KEY=secret

# Remove environment variables
danube rapids update my-api --rm-env OLD_KEY UNUSED_KEY

# Combine multiple updates
danube rapids update my-api \
  --profile large \
  --min-scale 2 \
  --max-scale 50 \
  --env NODE_ENV=production
```

`update` returns as soon as the change is accepted. To block until that change
has been rolled out (CLI 1.3.0 and later):

```bash
danube rapids update my-api --tag "$SHA" --wait --wait-timeout 10m
```

`--wait` exits non-zero only when the rollout settled as failed; a timeout means
it is still in progress. Changes sent while a rollout is running are queued
behind it, never dropped — send each change once, in a single `update`, rather
than as several quick calls. See [Rapids automation](rapids-automation) for
what the wait checks.

### Scaling options

| Flag | Description | Default |
|------|-------------|---------|
| `--min-scale <n>` | Minimum replicas (0 = scale-to-zero) | 0 |
| `--max-scale <n>` | Maximum replicas | 10 |
| `--scaling-metric <metric>` | `rps` or `concurrency` | `rps` |
| `--scaling-target <n>` | Target requests per second per pod | 100 |
| `--concurrency-target <n>` | Target concurrent requests per pod | 100 |
| `--timeout <seconds>` | Request timeout (max 3600) | 300 |

## Deleting a container

```bash
danube rapids rm my-api
```

Prompts for confirmation. Use `-y` to skip:

```bash
danube rapids rm my-api -y
```

## Deployment history

```bash
danube rapids deployments my-api
```

Shows all deployments with revision number, status, image:tag, traffic percentage, and deployment date.

## Usage and billing

```bash
danube rapids usage my-api
```

Displays:
- Total requests
- Total compute seconds
- Monthly cost

Filter by billing period:

```bash
danube rapids usage my-api --period 2026-01
```

## Complete workflow example

```bash
# Install the CLI
npm install -g @danubedata/cli

# Authenticate
danube login

# Create a container from a Docker image
danube rapids create \
  --name my-api \
  --type docker_image \
  --image myorg/my-api \
  --tag v1.0.0 \
  --profile small \
  --port 8080

# View the container
danube rapids show my-api

# Update environment variables
danube rapids update my-api \
  --env DATABASE_URL=postgres://db.example.com/mydb \
  --env API_KEY=sk-abc123

# Scale up for production
danube rapids update my-api \
  --profile medium \
  --min-scale 1 \
  --max-scale 20

# Check usage
danube rapids usage my-api

# View deployment history
danube rapids deployments my-api
```

## Next steps

- [CLI Overview](https://docs.danubedata.ro/cli-overview) — Installation, auth, and configuration
- [CLI: Static Sites](https://docs.danubedata.ro/cli-pages) — Static site deployment commands
- [Serverless Containers overview](https://docs.danubedata.ro/serverless-overview) — Full product reference
- [Serverless Invoking](https://docs.danubedata.ro/serverless-invoking) — Code examples for calling your containers

---

**Questions?** Contact support at support@danubedata.ro
