Modern cloud-native and DevOps workflows rely heavily on containerization to package applications along with all their dependencies, configurations, and libraries. This ensures consistency across development, staging, and production environments. Docker is the industry-standard containerization platform used to build, run, and manage containerized software.
Running Nginx in a container offers several key benefits:
By default, Docker containers are isolated from the host machine’s external network. They are assigned an internal IP address accessible only from the host or other containers on the same Docker network.
To allow external clients to access Nginx (which listens on port 80 by default inside the container), we must map the container’s port to a port on the host machine. This is done using the -p (or --publish) flag.
sequenceDiagram
actor Client as External Client (e.g. Browser/curl)
participant Host as Host Server (stapp03)
participant Docker as Docker Daemon (iptables/proxy)
participant Container as Nginx Container (nginx_3)
Client->>Host: Request http://stapp03:8080
Host->>Docker: Route incoming port 8080 traffic
Docker->>Container: Forward traffic to container port 80
Container-->>Docker: Send HTTP Response (Welcome to Nginx)
Docker-->>Host: Pass response
Host-->>Client: Respond to client
When a port is published, Docker sets up iptables rules or starts a docker-proxy process on the host to forward incoming connections to the container’s internal network interface.
stapp03)bannernginx_3nginx:alpine80 to host port 8080 (or 80)Establish an SSH connection from the Jump Host to App Server 3:
ssh banner@stapp03
Provide the server password when prompted.
Verify if Docker is installed and running on the target application server:
# Check service status
sudo systemctl status docker
If Docker is stopped, start it and optionally enable it to start on boot:
# Start Docker service
sudo systemctl start docker
# Enable Docker on boot
sudo systemctl enable docker
To deploy the Nginx container as specified in the challenge, use the standard docker run command.
docker run -d --name nginx_3 nginx:alpine
To expose the web server to the host network so external clients can access it on port 8080:
docker run -d --name nginx_3 -p 8080:80 nginx:alpine
docker run Options| Flag | Option | Description |
|---|---|---|
-d |
Detached Mode | Runs the container in the background and prints the container ID. The terminal remains free for further commands. |
--name nginx_3 |
Container Name | Assigns a custom name (nginx_3) to the container. If omitted, Docker assigns a random string name. |
-p 8080:80 |
Port Publishing | Maps <host_port>:<container_port>. Any traffic coming to port 8080 on the host will be forwarded to port 80 inside the container. |
nginx:alpine |
Image | Specifies the image to run. The :alpine tag indicates that the container uses a lightweight Alpine Linux distribution as its base. |
Ensure that the container was launched successfully and is in the Up state:
docker ps -a
Expected Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c2b8c9d0e1f2 nginx:alpine "/docker-entrypoint.…" 5 seconds ago Up 5 seconds 0.0.0.0:8080->80/tcp nginx_3
Use curl on the host machine to make an HTTP request to the exposed port:
curl http://localhost:8080
Expected Output (Nginx Welcome Page HTML):
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
If the container fails to start, or to view access requests, inspect the container logs:
docker logs nginx_3
To inspect environment variables, IP address configuration, and port bindings:
docker inspect nginx_3
Log out of the Application Server:
exit