Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Lab 18.1RH134, Chapter 18

Build an image-mode web server, update it and roll back

Level
Hard
90 min
Machines
server1
Status
Not started

Goal

Build a bootable container image with Apache, turn it into a KVM disk, boot a VM from it, then ship version 2 as an update — and roll it back.

Before you start

  • A RHEL 10 machine with KVM (virt-install) and at least 20 GiB free disk, registered, with access to registry.redhat.io (podman login registry.redhat.io).
  • A registry the VM can pull from. The easiest is a free account on quay.io (make the repository public), or a local registry on server1.
  • sudo dnf install -y container-tools virt-install.
  • In the tasks, replace quay.io/YOURNAME with your own registry path.

Tasks

  1. Write a Containerfile that starts from registry.redhat.io/rhel10/rhel-bootc:10.0, installs httpd, enables it, opens nothing else, and serves a page version 1 from /usr/share/web/html.
  2. Build the image as quay.io/YOURNAME/web-bootc:1.0, test that httpd is in it, and push it. Also tag and push it as :prod.
  3. Make a qcow2 disk with bootc-image-builder. Add a user admin in wheel with your SSH key.
  4. Boot a VM bootc1 from the disk. Log in as admin and check the image with bootc status. Make sure the VM follows the tag :prod.
  5. Change the page to version 2, build :2.0, and push it as :prod. Update bootc1 and reboot it.
  6. Roll bootc1 back to version 1 and reboot again.

Check your work

ssh admin@BOOTC1 'sudo bootc status'
curl -s http://BOOTC1/
ssh admin@BOOTC1 'rpm -q httpd; systemctl is-enabled httpd'
  • After task 5, curl prints version 2 and bootc status shows a rollback image.
  • After task 6, curl prints version 1.

Hints

Show the hints
  • /var is not updated by new images. Put the web page in /usr/share/web/html and point Apache there with a small config file in /etc/httpd/conf.d/.
  • bootc-image-builder runs as root and reads root's container storage: sudo podman pull the image first.
  • A VM made from the :1.0 disk follows :1.0. bootc switch quay.io/YOURNAME/web-bootc:prod makes it follow :prod.
  • On the KVM host, virsh domifaddr bootc1 shows the address of the VM. The libvirt network lets the host reach port 80 of the VM.

Solution

Show the solution
  1. The build folder.
    mkdir -p ~/web-bootc/html && cd ~/web-bootc
    echo "version 1" > html/index.html
    printf 'DocumentRoot "/usr/share/web/html"\n<Directory "/usr/share/web/html">\n    Require all granted\n</Directory>\n' > web.conf
    cat Containerfile
    FROM registry.redhat.io/rhel10/rhel-bootc:10.0
    RUN dnf -y install httpd && dnf clean all
    COPY web.conf /etc/httpd/conf.d/web.conf
    COPY html/ /usr/share/web/html/
    RUN systemctl enable httpd
  2. Build, test, push.
    podman login registry.redhat.io
    podman login quay.io
    podman build -t quay.io/YOURNAME/web-bootc:1.0 .
    podman run --rm quay.io/YOURNAME/web-bootc:1.0 rpm -q httpd
    podman push quay.io/YOURNAME/web-bootc:1.0
    podman tag quay.io/YOURNAME/web-bootc:1.0 quay.io/YOURNAME/web-bootc:prod
    podman push quay.io/YOURNAME/web-bootc:prod
  3. The disk image (as root).
    cat config.toml
    [[customizations.user]]
    name = "admin"
    key = "ssh-ed25519 AAAA...your-key"
    groups = ["wheel"]
    sudo podman pull quay.io/YOURNAME/web-bootc:prod
    mkdir -p output
    sudo podman run --rm -it --privileged --pull=newer --security-opt label=type:unconfined_t -v ./config.toml:/config.toml:ro -v ./output:/output -v /var/lib/containers/storage:/var/lib/containers/storage registry.redhat.io/rhel10/bootc-image-builder:latest --type qcow2 quay.io/YOURNAME/web-bootc:prod
  4. Boot the VM and check it.
    sudo cp output/qcow2/disk.qcow2 /var/lib/libvirt/images/bootc1.qcow2
    sudo virt-install --name bootc1 --memory 2048 --vcpus 2 --import --disk /var/lib/libvirt/images/bootc1.qcow2 --os-variant rhel10.0 --graphics none --noautoconsole
    sudo virsh domifaddr bootc1
    ssh admin@BOOTC1 'sudo bootc status'
    curl -s http://BOOTC1/
  5. Version 2 as an update.
    echo "version 2" > html/index.html
    podman build -t quay.io/YOURNAME/web-bootc:2.0 .
    podman push quay.io/YOURNAME/web-bootc:2.0
    podman tag quay.io/YOURNAME/web-bootc:2.0 quay.io/YOURNAME/web-bootc:prod
    podman push quay.io/YOURNAME/web-bootc:prod
    ssh admin@BOOTC1 'sudo bootc upgrade --apply'
    curl -s http://BOOTC1/
  6. Roll back.
    ssh admin@BOOTC1 'sudo bootc rollback && sudo systemctl reboot'
    curl -s http://BOOTC1/

My notes

No notes yet.

Lessons for this lab

Commands in this lab