Using Compose Files
This guide will show you how to launch multiple instances of a service together using a Compose file.
This can be achieved using kraft cloud compose
, a powerful subcommand within the Unikraft Cloud (UKC) platform that allows you to effortlessly launch instances onto the platform using the popular-format Compose file.
Prerequisites
Before you begin, ensure that you have the following prerequisites in place:
-
UKC Account: You must have an active account on UKC. Sign-up for the beta today!
-
Installed Kraft CLI: Ensure that you have the
kraft
CLI tool installed on your local machine. -
Configured Authentication: Authenticate your CLI with your Unikraft Cloud account by setting your access token using the
UKC_TOKEN
environmental variable or by using the--token
flag.
Quick Start
Using a Compose file with UKC is no different from using it with docker compose
or any other container runtime tool which supports the Compose file format.
-
Prepare your deployment by creating a Compose file. For example, let’s consider a simple Compose file that launches two instances of a service inside a new repository directory called
my-first-project
: -
Save the Compose file as
compose.yaml
in your project directory. -
Launch the services using the
kraft cloud compose
command:This command will read the
compose.yaml
file and launch the services together defined in the file.Similar to other
docker compose
commands, you can use the-d|--detach
flag which will then let the command return. Without this flag, the logs of each service will be tailed continuously to your terminal window.
Declaring memory reservation
It is possible to declare memory limits for each service in the Compose file by setting the mem_reservation
directive.
For example Grafana can be deployed with 1024MB of memory reservation:
Declaring networks
Networks in the context of a Compose file is deployed as a service.
By default, and when no networks
are specified, a default
one will be created and used.
You may wish to attach each service to a different network in order to provide different scaling policies.
To declaring a network will in turn create a service with the same name with the ${PROJECT_NEME}
as the prefix.
For example, the my-netwowrk
will be deployed as my-first-project-my-network
given the example compose.yaml
file from before:
Viewing the status of the services
To view the status of the services launched using the Compose file, you can use the kraft cloud compose ps
command when cd
’d into the project directory:
Next Steps
- Learn more about the Compose file format;
- See Go 1.22 with Redis deployed via
compose.yaml
example. - Build a compose project for UKC with
kraft cloud compose build
- Create a UKC deployment with
kraft cloud compose create
- Stop and remove the services in a UKC compose project deployment with
kraft cloud compose down
- Log the services in a UKC compose project deployment with
kraft cloud compose log
- List UKC deployments at a given path with
kraft cloud compose ls
- List the services of compose project deployed to UKC with
kraft cloud compose ps
- Push a UKC deployment service with
kraft cloud compose push
- Start a UKC deployment with
kraft cloud compose start
- Stop a UKC deployment with
kraft cloud compose stop
- Deploy services in a compose project to UKC with
kraft cloud compose up