Operations 3 min read

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.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Building and Running an Nginx Docker Image on CentOS

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.

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.

DevOpsContainerNginxCentOS
Practical DevOps Architecture
Written by

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.

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.