Files
floci/docs/configuration/docker-compose.md
T
Hector Ventura 023880b7d9 feat(parity): LocalStack drop-in compatibility (#696)
- Translate LocalStack env vars (LOCALSTACK_HOST, PERSISTENCE, LAMBDA_DOCKER_NETWORK, etc.)
  to Floci equivalents automatically at startup; opt out with LOCALSTACK_PARITY=false
- Serve /_localstack/init and /_localstack/health alongside /_floci/* equivalents
- Report executed scripts with path, state, and return_code in /_floci/init response
- Add /_aws/sqs/messages GET (non-destructive peek) and DELETE (purge) inspection endpoint
- Add /_aws/execute-api/{apiId}/{stageName} LocalStack-compat path for REST API invocation
- Add four-phase init hook lifecycle (boot/start/ready/stop) with dual-path discovery
  (/etc/floci/init/ and /etc/localstack/init/ compat paths)
- Install Python 3, AWS CLI, boto3 in standard image; wrap aws binary to pre-configure
  --endpoint-url=http://localhost:4566 so init scripts need no extra flags
- Wire entrypoint.sh + gosu privilege drop into all Dockerfile variants
- Add migration guide and update README, docker-compose, docker-images, SQS, and
  initialization-hooks docs
2026-05-04 01:15:59 -05:00

219 lines
9.0 KiB
Markdown

# Docker Compose
## Minimal Setup
For most services (SSM, SQS, SNS, S3, DynamoDB, Lambda, API Gateway, Cognito, KMS, Kinesis, Secrets Manager, CloudFormation, Step Functions, IAM, STS, EventBridge, Scheduler, CloudWatch) a single port is enough:
```yaml title="docker-compose.yml"
services:
floci:
image: floci/floci:latest
ports:
- "4566:4566"
volumes:
- ./data:/app/data
- ./init/start.d:/etc/floci/init/start.d:ro
- ./init/ready.d:/etc/floci/init/ready.d:ro
```
## Full Setup (with ElastiCache and RDS)
ElastiCache and RDS work by proxying TCP connections to real Docker containers (Valkey/Redis, PostgreSQL, MySQL). Those containers' ports must be reachable from your host, so additional port ranges must be exposed:
```yaml title="docker-compose.yml"
services:
floci:
image: floci/floci:latest
ports:
- "4566:4566" # All AWS API calls
- "6379-6399:6379-6399" # ElastiCache / Redis proxy ports
- "7001-7099:7001-7099" # RDS / PostgreSQL + MySQL proxy ports
volumes:
- /var/run/docker.sock:/var/run/docker.sock # required for Lambda, ElastiCache, RDS
- ./data:/app/data
environment:
FLOCI_SERVICES_DOCKER_NETWORK: my-project_default # (1)
FLOCI_HOSTNAME: floci # (2)
```
1. Set this to the Docker network name that your compose project creates (usually `<project-name>_default`). Floci uses it to attach spawned Lambda / ElastiCache / RDS containers to the same network.
2. Set this to the Compose service name when other containers, including
Lambda containers spawned by Floci, need to call Floci by Docker DNS.
!!! warning "Docker socket"
Lambda, ElastiCache, and RDS require access to the Docker socket (`/var/run/docker.sock`) to spawn and manage containers. If you don't use these services, you can omit that volume.
!!! note "ECR ports are not listed here intentionally"
ECR is backed by a separate `registry:2` sidecar container (`floci-ecr-registry`) that Floci starts and manages. That container binds its own host port (default `5100`) directly — adding `5100-5199` to the floci service's `ports` would conflict with the sidecar and break `docker push`/`docker pull`. See [Ports Reference → ECR](./ports.md#ports-51005199--ecr-registry) for details.
## Multi-container networking
By default, Floci embeds `localhost` in response URLs — for example, SQS queue
URLs look like `http://localhost:4566/000000000000/my-queue`. This is fine when
your application runs on the same machine, but breaks inside Docker Compose:
other containers cannot reach `localhost` of the Floci container.
Set `FLOCI_HOSTNAME` to the Compose service name so that Floci uses that name
in every URL it generates:
```yaml title="docker-compose.yml"
services:
floci:
image: floci/floci:latest
ports:
- "4566:4566"
environment:
FLOCI_HOSTNAME: floci # (1)
app:
build: .
environment:
AWS_ENDPOINT_URL: http://floci:4566
depends_on:
- floci
```
1. Must match the Compose service name so other containers can resolve it.
With this setting Floci returns URLs like
`http://floci:4566/000000000000/my-queue` that other containers in the same
network can reach.
This is also the recommended setting when Floci launches Lambda containers into
your Compose network via `FLOCI_SERVICES_LAMBDA_DOCKER_NETWORK` or
`FLOCI_SERVICES_DOCKER_NETWORK`. It makes the endpoint Floci injects into
Lambda containers, and response fields such as SQS `QueueUrl`, use a Docker
service name (`floci`) instead of a host-only `localhost` address.
This affects any response field that embeds the endpoint hostname:
- SQS — `QueueUrl`
- SNS — `TopicArn` callback URLs and subscription `SubscriptionArn` endpoints
- Any pre-signed URL or callback that is generated from `floci.base-url`
!!! tip "CI pipelines"
In GitHub Actions or GitLab CI where both your app and Floci run as
`services`, set `FLOCI_HOSTNAME` to the service name (e.g. `floci`) and
point your SDK at `http://floci:4566`.
## Initialization Hooks
Hook scripts can be mounted into the container to run custom setup and teardown logic at each lifecycle phase:
```yaml title="docker-compose.yml"
services:
floci:
image: floci/floci:latest-compat
ports:
- "4566:4566"
volumes:
- ./init/boot.d:/etc/floci/init/boot.d:ro # before storage loads, no AWS APIs
- ./init/start.d:/etc/floci/init/start.d:ro # after HTTP server is ready
- ./init/ready.d:/etc/floci/init/ready.d:ro # after all start hooks complete
- ./init/stop.d:/etc/floci/init/stop.d:ro # during shutdown, while HTTP is still up
```
Phases you don't need can be omitted. Use the `latest-compat` image when your scripts call `aws` or `boto3` — it includes the AWS CLI and boto3 with the local endpoint pre-configured, so no `--endpoint-url` flag is needed.
If you have existing LocalStack init scripts, mount them under the LocalStack-compat paths and they run unchanged:
```yaml title="docker-compose.yml"
volumes:
- ./localstack-init/ready.d:/etc/localstack/init/ready.d:ro
```
See [Initialization Hooks](./initialization-hooks.md) for execution behavior, script types, and configuration details.
## Persistence
By default Floci stores all data in memory — data is lost on restart. To persist data to disk, set the storage path and enable persistent mode:
```yaml
services:
floci:
image: floci/floci:latest
ports:
- "4566:4566"
volumes:
- ./data:/app/data
environment:
FLOCI_STORAGE_MODE: persistent
FLOCI_STORAGE_PERSISTENT_PATH: /app/data
```
### Using Named Volumes
Instead of bind-mounting a local directory, you can use Docker named volumes to keep your project directory clean:
```yaml
services:
floci:
image: floci/floci:latest
ports:
- "4566:4566"
volumes:
- floci-data:/app/data
environment:
FLOCI_STORAGE_MODE: persistent
FLOCI_STORAGE_PERSISTENT_PATH: /app/data
volumes:
floci-data:
```
Named volumes are managed entirely by Docker and won't create files in your repository. This works with both the JVM and native images.
## Docker Configuration
For Docker daemon socket, private registry authentication, log rotation, and network settings see [Docker Configuration](./docker.md).
## Environment Variables Reference
All `application.yml` options can be overridden via environment variables using the `FLOCI_` prefix with underscores replacing dots and dashes:
| Environment variable | Default | Description |
|---|---|---|
| `FLOCI_HOSTNAME` | _(none)_ | Hostname embedded in response URLs (SQS, SNS, pre-signed). Set to the Compose service name in multi-container setups |
| `FLOCI_DEFAULT_REGION` | `us-east-1` | AWS region reported in ARNs |
| `FLOCI_DEFAULT_ACCOUNT_ID` | `000000000000` | AWS account ID used in ARNs |
| `FLOCI_STORAGE_MODE` | `memory` | Global storage mode (`memory`, `persistent`, `hybrid`, `wal`) |
| `FLOCI_STORAGE_PERSISTENT_PATH` | `./data` | Directory for persistent storage |
| `FLOCI_DOCKER_DOCKER_HOST` | `unix:///var/run/docker.sock` | Docker daemon socket (shared by Lambda, RDS, ElastiCache) |
| `FLOCI_DOCKER_DOCKER_CONFIG_PATH` | `` | Path to dir with Docker's config.json (e.g. `/root/.docker`) |
| `FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__SERVER` | `` | Registry hostname for explicit credential entry 0 |
| `FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__USERNAME` | `` | Username for explicit credential entry 0 |
| `FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__PASSWORD` | `` | Password for explicit credential entry 0 |
| `FLOCI_SERVICES_LAMBDA_EPHEMERAL` | `false` | Remove Lambda containers after each invocation |
| `FLOCI_SERVICES_LAMBDA_DEFAULT_MEMORY_MB` | `128` | Default Lambda memory allocation |
| `FLOCI_SERVICES_LAMBDA_DEFAULT_TIMEOUT_SECONDS` | `3` | Default Lambda timeout |
| `FLOCI_SERVICES_LAMBDA_CODE_PATH` | `./data/lambda-code` | Where Lambda ZIPs are stored |
| `FLOCI_SERVICES_ELASTICACHE_PROXY_BASE_PORT` | `6379` | First ElastiCache proxy port |
| `FLOCI_SERVICES_ELASTICACHE_PROXY_MAX_PORT` | `6399` | Last ElastiCache proxy port |
| `FLOCI_SERVICES_ELASTICACHE_DEFAULT_IMAGE` | `valkey/valkey:8` | Default Redis/Valkey Docker image |
| `FLOCI_SERVICES_RDS_PROXY_BASE_PORT` | `7001` | First RDS proxy port |
| `FLOCI_SERVICES_RDS_PROXY_MAX_PORT` | `7099` | Last RDS proxy port |
| `FLOCI_SERVICES_RDS_DEFAULT_POSTGRES_IMAGE` | `postgres:16-alpine` | Default PostgreSQL image |
| `FLOCI_SERVICES_RDS_DEFAULT_MYSQL_IMAGE` | `mysql:8.0` | Default MySQL image |
| `FLOCI_SERVICES_RDS_DEFAULT_MARIADB_IMAGE` | `mariadb:11` | Default MariaDB image |
| `FLOCI_SERVICES_DOCKER_NETWORK` | _(none)_ | Docker network to attach spawned containers |
| `FLOCI_AUTH_VALIDATE_SIGNATURES` | `false` | Verify AWS request signatures |
## CI Pipeline Example
```yaml title=".github/workflows/test.yml"
services:
floci:
image: floci/floci:latest
ports:
- "4566:4566"
steps:
- name: Run tests
env:
AWS_ENDPOINT_URL: http://localhost:4566
AWS_DEFAULT_REGION: us-east-1
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
run: mvn test
```