Howto: Build OCI images with podman and import into Incus

Took me a while to get that done.

I assume here you want to build a image where the resulting container is running caddy.

Versions in use:

OS: Debian trixie
incus: 6.19.1
podman: 5.4.2

Prepare incus metadata

Add docker.io as remote

incus remote add docker.io --protocol oci https://docker.io

Copy the image

incus image copy docker.io:caddy:2.11-alpine local: --alias caddy/2.11-alpine

Export the upstream image

incus image export caddy/2.11-alpine caddy-incus.tar

Extract Metadata

mkdir caddy-metadata
cd caddy-metadata
tar xf ../caddy-incus.tar

Add properties to metadata.yaml

Make it to look like this where "properties.type": "oci" is the important part

{
  "architecture":"x86_64",
  "creation_date":1766018662,
  "expiry_date":0,
  "properties": {
    "type": "oci",
    "description": "my caddy (OCI)",
  },
  "templates":null
}

Create a tar out of the patched metadata

tar cf ../caddy-metadata.tar *
cd ..

Build the image with podman

podman build ./dir-with-a-dockerfile/ --output "type=tar,dest=caddy-rootfs.tar"

Import

incus image import caddy-metadata.tar caddy-rootfs.tar --alias my-caddy --reuse

Launch it

incus launch my-caddy my-cady
incus console --show-log my-caddy
7 Likes

Thanks for sharing.

1 Like

As a follow up, I’m using something like this to redeploy a container:

podman build ./dir-with-a-dockerfile/ --output "type=tar,dest=caddy-rootfs.tar"
incus image import caddy-metadata.tar caddy-rootfs.tar --alias my-caddy --reuse
incus rebuild -f local:my-caddy my-caddy

Now gonna find a minimal way to trigger that rebuild on git commits.

May I ask why you are not using Incus OCI support directly?

incus remote add docker.io --protocol oci https://docker.io
incus launch docker.io:caddy:2.11-alpine caddy

All fully supported by Incus and no need to deal with podman or anything else.

Ye, sure.

I build docker containers from a “Dockerfile” with podman and import the build without having to use a registry.

Hmm I could also setup a registry inside a incus container and use that one…

Done:

https://github.com/nuttyb-community/server

1 Like

Added docs for anyone interested into the server repo.

1 Like