Skip to content

How to test ZFS and sysv IPC annotations

Activate OCI hooks

Make sure /usr/local/etc/containers/containers.conf specifies the path to at least one OCI hooks directory and that it is not commented, e.g.:

hooks_dir = [
  "/usr/local/etc/containers/hooks.d",
]
# execute as root
mkdir -p /usr/local/etc/containers/hooks.d/

Add hooks

0. Clone the repo

git clone git@github.com:matias-pizarro/freebsd-oci-containers.git
cd freebsd-oci-containers

1. To mount persistent ZFS datasets in any given container

# execute as root
cp -pf annotations/hooks.d/zfs* /usr/local/etc/containers/hooks.d/

2. To enable sysv IPC in any given container

# execute as root
cp -pf annotations/hooks.d/sysv* /usr/local/etc/containers/hooks.d/

Test with a PostgreSQL container

1. Create a persistent ZFS dataset

# execute as root
zfs create -p \
    -o jailed=on \
    -o mountpoint=/var/db/postgres \
zroot/jailed/postgres

2. Initialize a PostgreSQL instance

(You can find the Containerfile used to build this image here)

# pg_major can be any major PostgreSQL version between 13 and 18 (included)
export pg_major=18
export postgres_image="ghcr.io/matias-pizarro/freebsd-oci-containers/freebsd-postgres${pg_major}:14.3"

podman run -it --rm \
    --annotation='sysv=true' \
    --annotation='zfs.dataset=zroot/jailed/postgres' \
    --env POSTGRES_PASSWORD=password \
    ${postgres_image} \
    chown -R 770:770 /var/db/postgres

podman run -it --rm \
    --annotation='sysv=true' \
    --annotation='zfs.dataset=zroot/jailed/postgres' \
    --env POSTGRES_PASSWORD=password \
    ${postgres_image} \
    service postgresql initdb

3. Run a PostgreSQL server instance

This instance will be available for connections from the host via a socket at /tmp/postgresql${pg_major}

podman run -it --rm \
    --annotation='sysv=true' \
    --volume /tmp/postgresql${pg_major}:/var/run/postgresql \
    --env POSTGRES_PASSWORD=password \
    ${postgres_image} \
        postgres -D /var/db/postgres/data${pg_major} \
            -c logging_collector=true \
            -c log_filename=postgres.log \
            -c log_destination=jsonlog \
            -k /var/run/postgresql

You can now connect to the server from another command line:

export pg_major=18
psql -h /tmp/postgresql${pg_major} -U postgres