Run a Service Inside a Container

DockerIntermediate
Practice Now

Introduction

In this challenge, you will practice managing containerized services on a Red Hat Enterprise Linux system. Your task is to build a custom container image for a web server, run a container based on that image, and ensure the service is accessible from the host system. This exercise covers fundamental skills for deploying and managing applications in containers, a core competency for a Red Hat Certified System Administrator.

Run a Service Inside a Container

In this challenge, you will build a custom container image that includes the Apache HTTP Server (httpd). You will create a simple HTML file to be served by the web server and run a container from your custom image. Finally, you will verify that the web service is running correctly and is accessible from the host.

Tasks

  • Build a custom container image that includes the Apache HTTP Server (httpd).
  • Create a simple HTML file to be served by the web server.
  • Run a container from your custom image and expose the web service.
  • Verify that the web service is running correctly and is accessible from the host.

Requirements

  • All files must be created in the ~/project directory.
  • Create a Dockerfile that uses the ubi9 base image.
  • The Dockerfile must install the httpd package.
  • Create an index.html file that contains the text Hello, World! inside an <h1> tag.
  • Build a container image and tag it as my-web-server.
  • Run a container in the background from the my-web-server image.
  • The container must be named my-web-server-run.
  • The web server inside the container must listen on port 80, and this port must be mapped to port 8080 on the host.

Example

After successfully starting the container, running the curl localhost:8080 command in your terminal should produce output similar to this:

<html>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

Summary

In this challenge, you have learned how to containerize a service on a Red Hat Enterprise Linux system. You successfully created a Dockerfile to define a custom environment, built a container image using podman, and ran a container to host a web server. You also practiced verifying the status of a running container and testing its network service. These are essential skills for modern application deployment and system administration.

✨ Check Solution and Practice