Quickstart
Create a new app
Go to the bunny.net dashboard, select Magic Containers, and click Add App. Select Single region deployment.
Add the ClickHouse container
Click Add Container and configure the image:
- Registry: Docker Hub
- Image:
clickhouse/clickhouse-server - Tag:
latest
CLICKHOUSE_DB=appCLICKHOUSE_USER=appCLICKHOUSE_PASSWORD= a strong passwordCLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
Add persistent volumes
In the Volumes section of the container settings, add two volumes:
- Name:
clickhouse-data, Mount path:/var/lib/clickhouse - Name:
clickhouse-logs, Mount path:/var/log/clickhouse-server
Always set a strong
CLICKHOUSE_PASSWORD, even if ClickHouse is not exposed
externally. Other containers in the same pod can access the network, and a
password protects against accidental or unauthorized access.Environment variables
The official ClickHouse image supports these environment variables:| Variable | Description | Default |
|---|---|---|
CLICKHOUSE_DB | Default database created on start | default |
CLICKHOUSE_USER | Username to create | default |
CLICKHOUSE_PASSWORD | Password for the user | - |
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT | Enable SQL-driven access management | 0 |
Connect from your app
In a multi-container setup, your app and ClickHouse share the same localhost network. ClickHouse exposes two interfaces:- HTTP: port
8123 - Native: port
9000
- HTTP
- Node.js
- Go
- Python
Multi-container example
A typical setup pairs ClickHouse with your application. When configuring the app, add two containers:App container
- Image: your app image (e.g.
ghcr.io/<your-username>/my-app:latest) - Endpoint: the port your app listens on
- Environment variables:
CLICKHOUSE_PASSWORD= a strong password
ClickHouse container
- Image:
clickhouse/clickhouse-server:latest - Volumes:
/var/lib/clickhouseand/var/log/clickhouse-server - Environment variables:
CLICKHOUSE_DB=appCLICKHOUSE_USER=appCLICKHOUSE_PASSWORD= a strong passwordCLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
Both containers share the same localhost network, so your app connects to
ClickHouse at
127.0.0.1:8123 (HTTP) or 127.0.0.1:9000 (native). See
multi-container apps for more details.External access
To connect to ClickHouse from outside Magic Containers (e.g. from your local terminal), add an Anycast endpoint:- Go to your app’s Endpoints tab and click Add New Endpoint
- Select Anycast as the type
- Set Container Port to
8123 - Set Exposed Port to
8123 - Click Add Endpoint
The exposed port and container port may differ. When connecting externally,
always use the exposed port shown in your endpoint configuration.
The
clickhouse-client uses the native protocol (port 9000). If you want to
use the native client externally, add a second Anycast endpoint for port
9000.