2. Containerizing and playing Clumsy-Bird
2. Containerizing and playing Clumsy-Bird ๊ด๋ จ
The Clumsy Bird Game has already been installed in the setup and We can't start with Building the Containers
Step 1
We'll use UBI9 as the base image for our container. We'll use the following Buildah command to create the container:
buildah from registry.access.redhat.com/ubi9/ubi
# ubi-working-container-1
Buildah adds -working-container-1
for unique name to avoid duplication after creating a container
Step 2
Now that the container is ready, install Apache and enable it as a service:
buildah run ubi-working-container-1 -- dnf -y install httpd
Step 3
Enable Apache service in container for start automatically after boot:
buildah run ubi-working-container-1 -- systemctl enable httpd
# Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service โ /usr/lib/systemd/system/httpd.service.
Step 4
Now that Apache is running in a container, copy Clumsy-bird game to Apache's document root (/var/www/html
) for access.
To copy the content, we'll use the following command:
buildah copy ubi-working-container-1 clumsy-bird /var/www/html
# 54246f8c1c828958d56ab873d8db8a890eaa29b88646b1177785495d285afb07
Step 5
Start container with web app running as a background service:
buildah config --port 80 --cmd "/usr/sbin/init" ubi-working-container-1
#
This command configures the container to:
- accept connections on port 80 (for HTTP access via web browser)
- run '
/usr/sbin/init
' at startup to start system services (such as Apache) in the background.
Step 6
Commit container changes using the command:
buildah commit ubi-working-container-1 clumsy-bird
# Getting image source signatures
# Copying blob c662a0c69917 skipped: already exists
# Copying blob 82541ac8604d done
# Copying config ad90e161ba done
# Writing manifest to image destination
# Storing signatures
# ad90e161bab65f9e034613771004e6a3952eaca78279f9bc7d2bdaa7c9ce2bd2
Step 7
Now it's time to run the container. We'll use the following command to run the container:
podman run --name clumsy-bird -d -p 8080:80 clumsy-bird
# 57e85d42b6df9382d038bdd814368c7d92ef95b4da3ba2068ae84eb45af28920
This command starts new container 'clumsy-bird' from image, run in detached mode with port mapping (-p 8080:80
) to route incoming connections to container's port 80.
Step 8
Now that it's running, we can go over to the next instruqt tab where weโll see the JavaScript application up and running at http://localhost:8080 You can also verify that the container is running with the command
podman ps
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 60232d68c3b4 localhost/moon-buggy:latest /usr/bin/moon-bug... 7 minutes ago Up 7 minutes moon-buggy
# 57e85d42b6df localhost/clumsy-bird:latest /usr/sbin/init 13 seconds ago Up 13 seconds 0.0.0.0:8080->80/tcp clumsy-bird