1. Pull the CentOS 7 Base Image
Start by pulling the official CentOS 7 image from Docker Hub:2. Create and Start a Container
- Create a container named
testfrom the CentOS 7 image: - Start it:
- Attach an interactive shell:
3. Install HTTPD and Customize the Web Page
Inside the container shell:You can test the Apache service within the container before committing:
4. Commit the Container to a New Image
-
Exit and stop the container:
-
Review container status:
-
Commit with metadata and a default
CMD. Here’s an overview of common flags:
| Flag | Description | Example |
|---|---|---|
| -a | Specify the author | -a "Yogesh Raheja" |
| -m | Add a commit message | -m "Add HTTPD and custom index" |
| -c | Set a Dockerfile instruction (e.g., CMD) | -c 'CMD ["httpd","-D","FOREGROUND"]' |
-
Run
docker commit:
5. Test Your Custom Image
Launch a container fromwebtest:v1, mapping port 80:
http://<DockerHostIP> in your browser. You should see:
6. Tag and Push to Docker Hub
-
Tag the image for your repository (replace
<your-dockerhub-username>): -
Log in to Docker Hub:
-
Push the tagged image:
v1 tag is published.
Congratulations! You’ve successfully created and published a custom Docker image using the
docker commit method.