> ## Documentation Index
> Fetch the complete documentation index at: https://docs.2501.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Docker Swarm

> Production deployment with Docker Swarm

## Prerequisites

### 1. Initialize Docker Swarm

On the manager node:

```bash theme={null}
docker swarm init
```

### 2. Join Worker Nodes (Optional)

On each worker node, run the join command provided by `docker swarm init`:

```bash theme={null}
docker swarm join --token <token> <manager-ip>:2377
```

### 3. Configure AWS & ECR on All Nodes

On **ALL nodes** (manager + workers):

1. Configure AWS credentials (see [Prerequisites](/0.4/deployment/overview#prerequisites))

2. Install ECR credential helper:

```bash theme={null}
sudo apt install -y amazon-ecr-credential-helper
```

3. Configure `~/.docker/config.json`:

```json theme={null}
{
  "credHelpers": {
    "605134458542.dkr.ecr.eu-west-3.amazonaws.com": "ecr-login"
  }
}
```

## Deployment

### Deploy Commands

```bash theme={null}
# Deploy
2501-infra deploy

# Stop services (scale to 0)
2501-infra deploy --stop

# Rolling restart
2501-infra deploy --restart

# Remove stack
2501-infra deploy --remove
```

For all deployment options:

```bash theme={null}
2501-infra deploy -h
```

### Non-Interactive Mode

For CI/CD pipelines, use the `--yes` flag:

```bash theme={null}
2501-infra deploy --yes
```

<Warning>
  With `--yes`, the command fails immediately on any error. Ensure all configuration is valid before using in automation.
</Warning>

## Post-Deployment

### Verify Services

```bash theme={null}
# Health checks
curl http://localhost:1337/health    # Engine
curl http://localhost:3000/health    # Command Center

# Check Swarm status
docker stack services 2501
```

### Create Initial Entities

<Tip>
  If you run `2501-infra deploy` without `--yes`, the CLI will interactively prompt you to create your first tenant, organization, and admin user.
</Tip>

If you used `--yes` mode, create entities manually:

```bash theme={null}
2501-infra tenant create --name "My Company"
2501-infra org create --name "Engineering" --tenant-id ten_xxx
2501-infra user create --email admin@company.com --role ADMIN --tenant-id ten_xxx --org-id org_xxx
```

For all entity management commands:

```bash theme={null}
2501-infra tenant -h
2501-infra org -h
2501-infra user -h
```

## Useful Docker Commands

```bash theme={null}
# Check service status
docker stack services 2501

# View logs
docker service logs -f 2501_engine
docker service logs -f 2501_command-center

# Scale services
docker service scale 2501_engine=4

# Rolling restart
docker service update --force 2501_engine
```
