Cloud Native 3 min read

How to Build Custom Docker Images Manually: From CentOS to Nginx

This guide walks through creating Docker images using both the discouraged docker commit method and the recommended Dockerfile approach, then demonstrates a step‑by‑step manual build of a custom Nginx image on a CentOS base, including essential commands and tips.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Build Custom Docker Images Manually: From CentOS to Nginx

1. Methods to create Docker images

Use docker commit command

Use docker build with a Dockerfile (recommended)

Although docker commit can capture a running container as an image, a Dockerfile provides far more flexibility and power.

2. Manually building an image

Typically you start from an existing base image such as centos, install the needed software, adjust configuration, and then commit the container as a new image.

Example: Build a custom Nginx image manually

docker pull centos
docker run -it --name mynginx centos
rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
yum install nginx -y
vi /etc/nginx/nginx.conf   # set "daemon off;"
exit
docker commit -m "nginx test mirror" eadfe0c0903d jkzhao/mynginx:v1
docker run -d -p 82:80 jkzhao/mynginx:v1 nginx

Important notes:

You must tag the image with v1; otherwise Docker will look for the latest tag.

The final nginx argument is the command executed inside the container; ensure you use the correct path if not using the default installation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

NginxDockerfileImage
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.