Skip to content

Instantly share code, notes, and snippets.

@mateuszkwiatkowski
Last active May 11, 2022 12:57
Show Gist options
  • Save mateuszkwiatkowski/3f299949ebf004a259b01dde867dbb29 to your computer and use it in GitHub Desktop.
Save mateuszkwiatkowski/3f299949ebf004a259b01dde867dbb29 to your computer and use it in GitHub Desktop.
Run OCI (docker) containers on FreeBSD

Install runj and containerd: pkg install runj containerd

Currently containerd port is missing rc.d script so we need to create one:

cat <<EOF > /usr/local/etc/rc.d/containerd
#! /bin/sh

# PROVIDE: containerd
# REQUIRE: DAEMON NETWORKING
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable containerd:
#
#containerd_enable="YES"

. /etc/rc.subr

name="containerd"
rcvar="containerd_enable"

load_rc_config $name

: ${containerd_enable:=NO}

pidfile="/var/run/${name}.pid"

command="/usr/sbin/daemon"
command_args="-r -S -t ${name} -T ${name} -P ${pidfile} /usr/local/bin/${name}"

PATH=$PATH:"/usr/local/bin/"
run_rc_command "$1"
EOF

Enable autostart of containerd:

chmod +x /usr/local/etc/rc.d/containerd
service containerd enable
service start enable

Now you can pull an image:

ctr image pull docker.io/kwiat/freebsd:13.0-RELEASE

And launch a container from it:

ctr run --runtime wtf.sbk.runj.v1 --rm docker.io/kwiat/freebsd:13.0-RELEASE my-freebsd sh -c "echo hello world"
hello world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment