# 在 Fly 上使用嵌入式副本

> 使用 [Turso Cloud 嵌入式副本](/features/embedded-replicas) 將 JavaScript 應用程式部署到 [Fly.io](https://www.fly.io/)。
> Canonical HTML: https://tursodb.cn/zh-tw/docs/features/embedded-replicas/with-fly/
> Upstream Source (MIT): https://docs.turso.tech/features/embedded-replicas/with-fly
> Language: zh-TW

---
![Koyeb 橫幅](/images/turso-docs/platforms/fly-banner.png)

## 先決條件

開始之前，請確認您已完成下列事項：

* [安裝 Turso CLI](/zh-tw/docs/cli/installation/)
* [註冊或登入 Turso Cloud](/zh-tw/docs/cli/authentication/#signup)
* [安裝 Fly.io CLI](https://fly.io/docs/hands-on/install-flyctl/)

**1. 找到您的應用程式**

您應該已經有一個使用 Turso Cloud 資料庫、且想要部署到 Fly 的應用程式。

**2. 使用 Fly 啟動**

使用 Fly CLI 啟動它：

```bash
fly launch
```

您的應用程式會自動部署到 Fly，但我們還沒準備好。

**3. 建立共享磁碟區**

現在建立一個用來存放嵌入式副本的磁碟區：

```bash
fly volumes create libsql_data
```

**4. 掛載並設定磁碟區**

`fly.toml` 和 `Dockerfile` 這兩個檔案是在您先前啟動時建立的。

更新 `fly.toml` 這個檔案，以掛載新的磁碟區：

```toml
[[mounts]]
source = "libsql_data"
destination = "/app/data"
```

接著在 `Dockerfile` 中，確認您有安裝並更新 `ca-certificates`：

```docker
RUN apt-get update -qq && \
    apt-get install -y ca-certificates && \
    update-ca-certificates
```

也請確認在任何 `COPY` 命令之後加上下列這行，以複製憑證：

```docker
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
```

**5. 設定 libSQL 用戶端**

您會想將 `url` 改成指向本機檔案，並將 `syncUrl` 設為您的 Turso Cloud 資料庫 URL：

```ts
import { createClient } from "@libsql/client";

const client = createClient({
  url: "file:/app/data/local.db",
  syncUrl: process.env.TURSO_DATABASE_URL,
  authToken: process.env.TURSO_AUTH_TOKEN,
  syncInterval: 60,
});
```

**6. 部署更新後的應用程式**

```bash
fly deploy
```
