Create a “Hello World” ROCK


Install Rockcraft

Install Rockcraft on your host:

sudo snap install rockcraft --classic --edge

Project Setup

Create a new directory and write the following into a text editor and save it as rockcraft.yaml:

# Metadata section

name: hello 
summary: Hello World 
description: The most basic example of a ROCK.
version: "1.0" 
license: Apache-2.0

base: bare
build-base: ubuntu:22.04
  amd64:  # Make sure this value matches your computer's architecture

# Parts section

    plugin: nil
      - hello_bins

This file instructs Rockcraft to build a ROCK that only has the hello binaries package slice (and its dependencies) inside, using Chisel. For more information about the parts section, check Rockcraft parts. The remaining YAML fields correspond to metadata that help define and describe the ROCK. For more information about all available fields check rockcraft.yaml.

Pack the ROCK with Rockcraft

To build the ROCK, run:

rockcraft pack

The output should look as follows:

Launching instance...
Retrieved base bare for amd64
Extracted bare:latest
Executed: pull hello
Executed: pull pebble
Executed: overlay hello
Executed: overlay pebble
Executed: build hello
Executed: build pebble
Executed: stage hello
Executed: stage pebble
Executed: prime hello
Executed: prime pebble
Executed parts lifecycle
Exported to OCI archive 'hello_1.0_amd64.rock'

At the end of the process, a file named hello_1.0_amd64.rock should be present in the current directory. That’s your ROCK, in oci-archive format (a tarball).

Run the ROCK in Docker

First, import the recently created ROCK into Docker:

sudo /snap/rockcraft/current/bin/skopeo --insecure-policy copy oci-archive:hello_1.0_amd64.rock docker-daemon:hello:1.0

Now run the hello command from the ROCK:

docker run --rm hello:1.0 exec hello -t

Which should print:

hello, world