Building and Running an Nginx Docker Image on CentOS
This tutorial demonstrates how to create a Dockerfile on a CentOS host, build an Nginx image, run the container, and verify its operation, while highlighting the importance of specifying an entrypoint or CMD in the Dockerfile.
This guide walks through creating a Dockerfile on a CentOS node, building an Nginx image, and running it as a container.
First, create a working directory and open the Dockerfile for editing:
mkdir dockerfile cd dockerfile/Write the following Dockerfile content:
FROM centos MAINTAINER hahashen RUN yum -y install wget RUN yum -y install nginx COPY index.html /usr/share/nginx/html/ EXPOSE 80 ENTRYPOINT ["/usr/sbin/nginx","-g","daemon off;"]Build the image with: docker build -t="hahashen/nginx:v1" . After the build completes, verify the image list: docker images Run the container: docker run -d -p 80 --name dotnet hahashen/nginx:v1 Check running containers with: docker ps The output shows the container ID, image, command, status, and port mapping (e.g., 0.0.0.0:49154->80/tcp).
Note that the Dockerfile must include an ENTRYPOINT or CMD to keep the Nginx process alive.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
