Skip to main content
In this tutorial, you’ll learn how to build an HTTPD webserver image on top of a CentOS 7 base image using the Docker commit method. By the end, you’ll have a reusable image that includes your custom Apache configuration and index page.

1. Pull the CentOS 7 Base Image

Start by pulling the official CentOS 7 image from Docker Hub:
You should see output like:
Verify it’s available locally:
Example:

2. Create and Start a Container

  1. Create a container named test from the CentOS 7 image:
  2. Start it:
  3. Attach an interactive shell:

3. Install HTTPD and Customize the Web Page

Inside the container shell:
This installs Apache HTTPD and replaces the default index page.
You can test the Apache service within the container before committing:

4. Commit the Container to a New Image

  1. Exit and stop the container:
  2. Review container status:
  3. Commit with metadata and a default CMD. Here’s an overview of common flags:
  1. Run docker commit:
You’ll get a new image ID, for example:
Verify the image list:
Expected:

5. Test Your Custom Image

Launch a container from webtest:v1, mapping port 80:
Confirm it’s running:
Open http://<DockerHostIP> in your browser. You should see:
This verifies that your HTTPD configuration and custom index page are baked into the image.

6. Tag and Push to Docker Hub

  1. Tag the image for your repository (replace <your-dockerhub-username>):
  2. Log in to Docker Hub:
  3. Push the tagged image:
Visit your Docker Hub repository to confirm the v1 tag is published.
Congratulations! You’ve successfully created and published a custom Docker image using the docker commit method.

References

Watch Video