How to Run an NGINX Web Server in Docker and Access it Via a Web Browser?
Share
Condition for Run an NGINX Web Server in Docker and Access it Via a Web Browser
Description: This task helps you to pull the official NGINX image from Docker Hub, start it as a container, and map its port to your local machine. Then, you will access the default NGINX welcome page in a browser to verify it’s running.
Steps
Step 1 — Pull NGINX Image
Description: Download the latest official NGINX image from Docker Hub so you can run a web server container.
Command:
docker pull nginx
Step 2 — Run NGINX Container
Description: Start an NGINX container in detached mode and map the container’s port 80 to your host port 8081.
Command:
docker run -d -p 8081:80 nginx
Step 3 — Verify Container is Running
Description: Ensure that the NGINX container is running successfully.
Command:
docker ps
Step 4 — Access NGINX in Browser
Description: Open a web browser and visit the mapped port on your host to see the NGINX welcome page.
Action:
Navigate to: http://localhost:8081
Step 5 — Confirm NGINX Welcome Page
Description: Verify that the default NGINX landing page is displayed, confirming the container is serving HTTP requests correctly.
Action:
You should see the NGINX welcome page in your browser.