Use Case - Running a bootc container providing Apache HTTP server
In this example, we will build a container image from a Containerfile and we will then use it as a source for a VM.
The Containerfile in the example:
- Updates packages
- Installs tmux and mkpasswd to create a simple user password
- Creates a bootc-user user in the image
- Adds the wheel group to sudoers
- Installs Apache Server
- Enables the systemd unit for httpd
- Adds a custom index.html
Review Containerfile.httpd
MAINTAINER Alessandro Rossi <al.rossi87@gmail.com>
FROM registry.redhat.io/rhel9/rhel-bootc:9.5
RUN dnf -y update && dnf -y install tmux mkpasswd
RUN pass=$(mkpasswd --method=SHA-512 --rounds=4096 redhat) && useradd -m -G wheel bootc-user -p $pass
RUN echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wheel-sudo
RUN dnf -y install httpd && \
systemctl enable httpd && \
mv /var/www /usr/share/www && \
sed -ie 's,/var/www,/usr/share/www,' /etc/httpd/conf/httpd.conf
COPY files/index.html /usr/share/www/html/index.html
EXPOSE 80
Building the image
From the root folder of the repository, switch to the use case directory:
To build the image:
Testing the image
You can now test it using:
Note: The "-p 8080:80" part forwards the container's http port to the port 8080 on the host to test that it is working.
The container will now start and a login prompt will appear:
On another terminal tab or in your browser, you can verify that the httpd server is working and serving traffic.
Terminal
Browser
Exploring the container
If you are curious, you can easily log-in to the container using the prompt coming from the execution and the bootc-user/redhat user and password.
From here, you can verify that:
- The user has sudo privileges
- There's systemd running
bash-5.1# systemctl status | more
● rhel-bootc-httpd
State: running
Units: 234 loaded (incl. loaded aliases)
Jobs: 0 queued
Failed: 0 units
Since: Fri 2024-07-19 08:19:28 UTC; 1min 57s ago
systemd: 252-32.el9_4
- Apache is loaded as a systemd unit
bash-5.1# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled)
Active: active (running) since Fri 2024-07-19 08:19:29 UTC; 2min 28s ago
Docs: man:httpd.service(8)
Main PID: 90 (httpd)
Status: "Total requests: 1; Idle/Busy workers 100/0;Requests/sec: 0.00719; Bytes served/sec: 2 B/sec"
Tasks: 177 (limit: 1638)
Memory: 22.0M
CPU: 159ms
CGroup: /system.slice/httpd.service
├─ 90 /usr/sbin/httpd -DFOREGROUND
├─115 /usr/sbin/httpd -DFOREGROUND
├─117 /usr/sbin/httpd -DFOREGROUND
├─118 /usr/sbin/httpd -DFOREGROUND
└─119 /usr/sbin/httpd -DFOREGROUND