Container Building (OCI SDK)
RBS includes a built-in OCI SDK for building container images as part of your build process. No Docker daemon or Dockerfile is required — images are assembled programmatically using RBS DSL primitives.Why RBS for Containers?
| Feature | RBS OCI | Docker Build | Buildpacks |
|---|---|---|---|
| Daemon Required | No | Yes | Yes |
| Reproducible | Yes (hermetic) | Partial | Partial |
| Layer Control | Full | Limited | None |
| Build Integration | Native | Separate tool | Separate tool |
| Base Image Pull | Built-in | Built-in | Built-in |
Quick Start
Using High-Level Rules
The simplest way to build container images:OCI SDK Primitives
For advanced use cases, the OCI SDK provides low-level primitives accessible viactx.oci within custom rules.
ctx.oci.create_layer()
Creates a single OCI layer from files.
Layer Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Unique name for the layer. |
files | dict | Mapping of destination_path: source_path. |
tar | string | Path to an existing tar file to use as the layer. |
directory | string | Sets the working directory (WORKDIR). |
entrypoint | list | Sets the container entrypoint. |
cmd | list | Sets the container CMD (default arguments). |
env | dict | Environment variables to set. |
ports | list | Ports to expose. |
user | string | User/group to run as (e.g., "1000:1000"). |
labels | dict | OCI image labels. |
ctx.oci.pull()
Pulls a base image from a registry.
ctx.oci.write_docker_tar()
Assembles layers into a Docker-compatible image tarball.
ctx.oci.image_builder()
A fluent builder API for creating images step by step.
Complete Examples
Java Spring Boot Container
Node.js Express Container
Python Django Container
Multi-Stage Build (Custom Rule)
For maximum control over the image layout:Image Optimization Tips
Layer Ordering
Layer Ordering
Place rarely-changing content (OS packages, runtime dependencies) in early layers and frequently-changing content (application code) in later layers. This maximizes layer cache reuse.
Minimal Base Images
Minimal Base Images
Use slim or distroless base images to reduce image size and attack surface:
eclipse-temurin:17-jre-alpineinstead ofeclipse-temurin:17-jdknode:20-sliminstead ofnode:20python:3.11-sliminstead ofpython:3.11
Multi-Platform Images
Multi-Platform Images
Build images for multiple platforms by specifying the target platform:
Non-Root User
Non-Root User
Always run containers as a non-root user: