rkt can discover, retrieve, verify, and store images without root privileges. This capability means that you're not downloading content from the internet as root.
Here is the command to fetch an Alpine Linux image:
core@core-01 ~ $ rkt fetch quay.io/coreos/alpine-sh
rkt: searching for app image quay.io/coreos/alpine-sh
rkt: remote fetching from URL "https://quay.io/c1/aci/quay.io/coreos/alpine-sh/latest/aci/linux/amd64/"
prefix: "quay.io/coreos/alpine-sh"
key: "https://quay.io/aci-signing-key"
gpg key fingerprint is: BFF3 13CD AA56 0B16 A898 7B8F 72AB F5F6 799D 33BC
Quay.io ACI Converter (ACI conversion signing key)
Key "https://quay.io/aci-signing-key" already in the keystore
rkt: downloading signature from https://quay.io/c1/aci/quay.io/coreos/alpine-sh/latest/aci.asc/linux/amd64/
Downloading signature: [=======================================] 473 B/473 B
Downloading ACI: [=============================================] 2.65 MB/2.65 MB
rkt: signature verified:
Quay.io ACI Converter (ACI conversion signing key)
sha512-a2fb8f390702d3d9b00d2ebd93e7dd1c
core@core-01 ~ $
After the image is located in the local image store, we can run it:
core@core-01 ~ $ sudo rkt run --interactive quay.io/coreos/alpine-sh -- /bin/sh
rkt: using image from file /usr/share/rkt/stage1-coreos.aci
rkt: using image from local store for image name quay.io/coreos/alpine-sh
/ # ps
PID USER TIME COMMAND
1 root 0:00 /usr/lib/systemd/systemd --default-standard-output=tty --
2 root 0:00 /usr/lib/systemd/systemd-journald
4 root 0:00 /bin/sh -c /bin/sh /bin/sh
5 root 0:00 /bin/sh
6 root 0:00 ps
/ # ls /
bin etc lib media proc run sys usr
dev home linuxrc mnt root sbin tmp var
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.2.3
PRETTY_NAME="Alpine Linux v3.2"
HOME_URL="http://alpinelinux.org"
BUG_REPORT_URL="http://bugs.alpinelinux.org"
/ #
From inside the container, ps
and ls
show the isolated process namespace and container filesystem. The os-release
file shows the container's OS personality.
Outside the container, the host systemd
can monitor and arrange logging and other lifecycle management for rkt pods.
Printing system-wide status shows systemd managing the pod's execution as a system service, and the container's isolation within a cgroups
machine slice, including the nested systemd governing process lifecycles inside the container:
core@core-02 ~ $ systemctl status
● core-02
State: running
Jobs: 0 queued
Failed: 0 units
Since: Tue 2016-02-02 19:35:01 UTC; 10h ago
CGroup: /
├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 2
├─machine.slice
│ └─machine-rkt\x2dcd642877\x2d8ef5\x2d4b0a\x2d8202\x2d2c6c9415b9cf.s
│ ├─1857 /usr/lib/systemd/systemd --default-standard-output=tty --l
│ └─system.slice
│ ├─systemd-journald.service
│ │ └─1860 /usr/lib/systemd/systemd-journald
│ └─alpine-sh.service
│ ├─1864 /bin/sh -c /bin/sh /bin/sh
│ └─1866 /bin/sh
└─system.slice
├─dbus.service
│ └─643 /usr/bin/dbus-daemon --system --address=systemd: --nofork -
├─update-engine.service
│ └─649 /usr/sbin/update_engine -foreground -logtostderr
├─system-sshd.slice
│ ├─sshd@0-10.0.2.15:22-10.0.2.2:64676.service
│ │ ├─ 819 sshd: core [priv]
core@core-02 ~ $
Since this is a view into the entire CoreOS machine, two default services, sshd
, and the update-engine
that handles CoreOS software updates, are visible as well. This illustrates the identical management interface for both system-level and containerized applications enabled by the rkt process model.
machinectl
is systemd's tool for viewing VMs and containers running under its control. The command reveals the transient name assigned to our rkt instance, which is a container in this instance:
core@core-02 ~ $ machinectl list
MACHINE CLASS SERVICE
rkt-cd642877-8ef5-4b0a-8202-2c6c9415b9cf container nspawn
1 machines listed.
Given the pod's machine name, we can stop the pod with the machinectl tool:
core@core-02 ~ $ sudo machinectl poweroff rkt-cd642877-8ef5-4b0a-8202-2c6c9415b9cf
core@core-02 ~ $ machinectl list
MACHINE CLASS SERVICE
0 machines listed.
core@core-02 ~ $
Long-running rkt pods can be managed as systemd services, with standard tools and practices. An automatic nested systemd manages process lifecycles inside the container. Container apps can be inspected with familiar tools, and even integrated with local management scripts.
In this quick example, we're constructing an on-the-fly service with systemd-run
. The status
command lists the PID tree as well as the first few lines of logs.
In this example, running journalctl -u run-1907.service
would yield the full log stream.
core@core-02 ~ $ sudo systemd-run --slice=machine rkt run --net=host quay.io/josh_wood/caddy
Running as unit run-1907.service.
core@core-02 ~ $ systemctl status run-1907.service
● rkt-caddy.service - /bin/rkt run --net=host quay.io/josh_wood/caddy
Loaded: loaded (/run/systemd/system/run-1907.service; static; vendor preset: disabled)
Drop-In: /run/systemd/system/run-1907.service.d
└─50-Description.conf, 50-ExecStart.conf, 50-Slice.conf
Active: active (running) since Wed 2016-02-03 06:37:48 UTC; 24s ago
Main PID: 1908 (ld-linux-x86-64)
CGroup: /machine.slice/run-1907.service
├─1908 stage1/rootfs/usr/lib/ld-linux-x86-64.so.2 stage1/rootfs/us...
├─1928 /usr/lib/systemd/systemd --default-standard-output=tty --lo...
└─system.slice
├─caddy.service
│ └─1933 /bin/caddy
└─systemd-journald.service
└─1929 /usr/lib/systemd/systemd-journald
Feb 03 06:37:50 core-02 rkt[1908]: Downloading signature: 473 B/473 B
Feb 03 06:37:51 core-02 rkt[1908]: Downloading ACI: 0 B/4.54 MB
Feb 03 06:37:51 core-02 rkt[1908]: Downloading ACI: 16.4 KB/4.54 MB
Feb 03 06:37:52 core-02 rkt[1908]: Downloading ACI: 819 KB/4.54 MB
Feb 03 06:37:53 core-02 rkt[1908]: Downloading ACI: 2.96 MB/4.54 MB
Feb 03 06:37:54 core-02 rkt[1908]: Downloading ACI: 4.54 MB/4.54 MB
Feb 03 06:37:54 core-02 rkt[1908]: rkt: signature verified:
Feb 03 06:37:54 core-02 rkt[1908]: Quay.io ACI Converter (ACI conversion si...o>
Feb 03 06:37:55 core-02 rkt[1908]: [38154.032938] caddy[4]: Activating priv...e.
Feb 03 06:37:55 core-02 rkt[1908]: [38154.035398] caddy[4]: :2015
Hint: Some lines were ellipsized, use -l to show in full.
core@core-02 ~ $ sudo systemctl stop run-1907.service
rkt can fetch Docker images from common Docker registries, and convert and execute them on the fly. To simplify this example, we direct rkt to skip image signature verification.
core@core-02 ~ $ sudo rkt run --insecure-options=image --interactive docker://busybox -- /bin/sh
rkt: using image from local store for image name coreos.com/rkt/stage1-coreos:0.16.0
rkt: remote fetching from URL "docker://busybox"
Downloading sha256:eeee0535bf3: [==============================] 676 KB/676 KB
Downloading sha256:a3ed95caeb0: [==============================] 32 B/32 B
/ # ps
PID USER TIME COMMAND
1 root 0:00 /usr/lib/systemd/systemd --default-standard-output=tty --
2 root 0:00 /usr/lib/systemd/systemd-journald
4 root 0:00 /bin/sh -c "sh" /bin/sh
5 root 0:00 sh
7 root 0:00 ps
/ # ls /
bin dev etc home proc root sys tmp usr var
/ # uname -a
Linux rkt-a6470cfe-7b6c-498c-917d-a254a312f0aa 4.4.0-coreos-r2 #2 SMP Fri Jan 29 22:00:35 UTC 2016 x86_64 GNU/Linux
~ #
Running Docker images with rkt gains you better integration with your init system while preserving your existing build process.
Trying out all the features available in rkt can leave a lot of experimental pods lying around. The rkt gc
command reaps exited pods and container images from the local store after a configurable grace period. This is easy to automate with a periodic schedule to keep the rkt store tidy:
core@core-02 ~ $ sudo rkt list
UUID APP IMAGE NAME STATE NETWORKS
81627cc6 caddy quay.io/josh_wood/caddy:latest exited
cd642877 alpine-sh quay.io/coreos/alpine-sh:latest exited
d65abad6 alpine-sh quay.io/coreos/alpine-sh:latest exited
core@core-02 ~ $ sudo rkt gc
Moving pod "81627cc6-6d19-48db-8a29-d2e043d060f7" to garbage
Moving pod "cd642877-8ef5-4b0a-8202-2c6c9415b9cf" to garbage
Moving pod "d65abad6-2951-4c5a-a32d-c851145d3320" to garbage
Pod "81627cc6-6d19-48db-8a29-d2e043d060f7" not removed: still within grace period (30m0s)
Pod "cd642877-8ef5-4b0a-8202-2c6c9415b9cf" not removed: still within grace period (30m0s)
Pod "d65abad6-2951-4c5a-a32d-c851145d3320" not removed: still within grace period (30m0s)
Three containers have exited, with all of their processes terminated, but remain in the rkt management list until inactive longer than the garbage collection grace period — 30 minutes by default.
To remove these immediately, reduce the grace period to zero:
core@core-02 ~ $ sudo rkt gc --grace-period=0
Garbage collecting pod "81627cc6-6d19-48db-8a29-d2e043d060f7"
Garbage collecting pod "cd642877-8ef5-4b0a-8202-2c6c9415b9cf"
Garbage collecting pod "d65abad6-2951-4c5a-a32d-c851145d3320"
core@core-02 ~ $ sudo rkt list
UUID APP IMAGE NAME STATE NETWORKS
core@core-02 ~ $
All exited containers have been removed. Images can be garbage-collected after a configurable grace period in the same manner. Both storage and general system resource consumption are kept trim and tidy.