Skip to main content
There are a couple templates that we offer to allow you to get started without any heavy lifting. The steps to get started are simple and easy to test in a few minutes.

Before You Start

Make sure you have Docker Desktop or OrbStack started before you begin.

Also, make sure you have gone through the Sign-up for Cloud Account section before continuing.

Phala Cloud Next.js Starter

This is a template for developing a Next.js-based app with boilerplate code targeting deployment on Phala Cloud and dstack. It includes the SDK by default to make integration with TEE features easier. This repo also includes a default Dockerfile and docker-compose.yml for deployment.

Requirements

  • Node >= v18.18
  • yarn
  • Docker or Orbstack

Development

First, you need to clone this repo:
Next, let’s initialize the development environment:
We also need to download the dstack simulator:
Once the simulator is running, you need to open another terminal to start your Next.js development server:
By default, the Next.js development server will listen on port 3000. Open http://127.0.0.1:3000/ in your browser and check.This repo also includes code snippets for the following common use cases:
  • /api/tdx_quote: The reportdata is test and generates the quote for attestation report via getQuote API.
  • /api/tdx_quote_raw: The reportdata is Hello DStack! and generates the quote for attestation report. The difference from /api/dx_quote is that you can see the raw text Hello DStack! in Attestation Explorer.
  • /api/eth_account/address: Using the getKey API to generate a deterministic wallet for Ethereum, a.k.a. a wallet held by the TEE instance.
  • /api/solana_account/address: Using the getKey API to generate a deterministic wallet for Solana, a.k.a. a wallet held by the TEE instance.
  • /api/info: Returns the TCB Info of the hosted CVM.

Build and Publish to Docker Registry

You need to build the image and push it to DockerHub for deployment. The following instructions are for publishing to a public registry via DockerHub:
For this to be logged into Docker to push to registry. Run docker login to login in the CLI.

Build and Publish with Docker CLI

Now we have an official docker image for our nextjs app. Let’s deploy to Phala Cloud now.

Deploy to Phala Cloud

You can copy and paste the docker-compose.yml file from this repo to see the example up and running.

Deploy in Phala UI

Go to your Phala Cloud dashboard and click Deploy. You will have an option for deploying via docker compose file. Click on this option to deploy.
Phala Cloud Deploy page with docker-compose editor
You will come to a CVM configuration page. Click on Advanced and replace the default docker compose contents with the following (Make sure to replace the <docker-username>with your own:
Screenshot

Docker Compose Example

Deploy via Phala Cloud CLI

For those using the CLI, you can deploy from the terminal with:
Make sure to change the image field to match your published docker image (ex: 0xii/my-app:latest)

Interact with Your Next.js App in Phala Cloud

Your application should be deployed now to your Phala Cloud dashboard. Go to the Network tab to be able to open your application.
Screenshot
Screenshot
Python Template

Phala Cloud Python Starter

This is a template for developing a FastAPI-based app with boilerplate code targeting deployment on Phala Cloud and dstack. It includes the SDK by default to make integration with TEE features easier. This repo also includes a default Dockerfile and docker-compose.yml for deployment.

Development

In this tutorial, we’ll start with venv and pip. First, you need to clone this repo:
Next, let’s initialize the development environment with venv & pip:
We also need to download the dstack simulator:
Once the simulator is running, you need to open another terminal to start your FastAPI development server:
By default, the FastAPI development server will listen on port 8000. Open http://127.0.0.1:8000/tdx_quote in your browser to get the quote with reportdata test.

Build and Publish with Docker CLI

Now we have an official docker image for our Python app. Let’s deploy to Phala Cloud now.

Deploy to Phala Cloud

You can copy and paste the docker-compose.yml file from this repo to see the example up and running.

Deploy in Phala UI

Go to your Phala Cloud dashboard and click Deploy. You will have an option for deploying via docker compose file. Click on this option to deploy.
Phala Cloud Deploy page with docker-compose editor
You will come to a CVM configuration page. Click on Advanced and replace the default docker compose contents with the following (Make sure to replace the <docker-username>with your own:
Screenshot
Now you can interact with your application by going to the Network tab and making calls like the following.
Screenshot
Screenshot

/tdx_quote

Screenshot

/derive_key

And output of GET /eth_account
Output of GET /sol_account

Conclusion

The last 2 tutorials were key to understanding the basics of deploying a Docker app on a TEE Server. Now you are ready to start building on dstack! For more info on the design of dstack, check out the Design Documents.