Digital Ocean App Platform 🌊
Before you get started, if you haven't already completed these steps, you'll have to:
- Create a free Digital Ocean account (or sign in with Google or GitHub).
- Install Docker on your machine and run it. You can verify it is set up correctly by running:
(If Docker is running, the command will print the images on your machine. If not, it will print something like
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?)
Install the Digital Ocean CLI (doctl) on your machine.
Create a Digital Ocean API Token for your account with read and write access, then use it to give
doctlaccess to your account by running (it will prompt you for the access token):
doctl auth init --context [NAME]
[NAME]: A new name for the authentication context.
You can switch authentication contexts in
doctl buy running:
doctl auth switch --context [NAME]
- Give Docker permission to push images to Digital Ocean by running:
doctl registry login
- Create a Container Registry. This can be done in the Digital Ocean console, or by running:
doctl registry create [REGISTRY_NAME] --region [REGION]
[REGISTRY_NAME]: A name for the newly created registry.
[REGION]: The Digital Ocean region the registry should reside in (ex: sfo1)
Be creative - registry names must be unique across all Digital Ocean container registries.
- Build your API for production use by running:
This will create a
/build directory with all the files needed to deploy your API.
- Build your API using Docker by running:
docker build build \
[REGISTRY]: The name of the registry you created eariler
[IMAGE_NAME]: A name given to this image to identify it in the registry
This command will build the Docker image on your machine and can take up to a few minutes.
Since this step requires building an image on your own hardware make sure the image is compatible with the hardware used by Digital Ocean before proceeding.
For example, if you build on an M1 CPU, the generated image will not be able to run on an Intel CPU.
We recommend using an automated workflow via GitHub Actions to automate deployments and ensure a consistent environment when building your image.
- Push the image to Container Registry by running:
docker push registry.digitalocean.com/[REGISTRY]/[IMAGE_NAME]
You should now see your repository in the Container Registry page
Create your App by following these instructions.
Congratulations! You have successfully built and deployed your API to App Platform. You can now access your API via the URL at the top of the app’s overview page 🎉