Skip to content

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:

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.

  1. 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:

    services:
    web:
    image: ${UKC_USER}/webapp:latest
    build: .
    ports:
    - "443:8080"
    environment:
    - DB_HOST: my-first-project-db.internal
    db:
    image: postgres:latest
    environment:
    POSTGRES_PASSWORD: example
  2. Save the Compose file as compose.yaml in your project directory.

  3. Launch the services using the kraft cloud compose command:

    Terminal window
    kraft cloud compose up

    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:

services:
grafana:
image: grafana:latest
mem_reservation: 1024M

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:

networks:
my-network:
services:
grafana:
image: grafana:latest
networks:
- my-network

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:

Terminal window
kraft cloud compose ps
Terminal window
NAME FQDN STATE STATUS IMAGE MEMORY ARGS BOOT TIME
http-go122-redis-app http-go122-redis-default... running since 42secs alex/http-go122-redis-... 128 MiB /server 19.14 ms
http-go122-redis-redis http-go122-redis-default... running since 42secs redis@sha256:29116655b... 128 MiB /usr/bin/redis-server ... 21.69 ms

Next Steps