The Nautilus DevOps team is planning to host an application on a nginx-based container. There are number of tickets already been created for similar tasks. One of the tickets has been assigned to set up a nginx container on Application Server 3 in Stratos Datacenter. Please perform the task as per details mentioned below:
a. Pull nginx:alpine docker image on Application Server 3.
b. Create a container named cluster using the image you pulled.
c. Map host port 3001 to container port 80. Please keep the container in running state.
📋 Docker Ports Mapping
Challenge Requirements:
- On App Server 3
- Pull
nginx:alpineimage - Create container named
cluster - Map host port
3001to container port80 - Keep container running
🔧 Step-by-Step Solution
Step 1: SSH to App Server 3
ssh banner@stapp03
# Password: BigGr33n
Step 2: Switch to Root (if needed)
sudo -i
# Password: BigGr33n
Step 3: Check Docker Status
# Check Docker version
docker --version
# Check Docker service status
sudo systemctl status docker
Step 4: Pull the Nginx Alpine Image
# Pull the nginx:alpine image
docker pull nginx:alpine
# Verify the image is pulled
docker images | grep nginx
Step 5: Create and Run the Container with Port Mapping
# Create and run container with port mapping
docker run -d --name cluster -p 3001:80 nginx:alpine
# The syntax is: docker run -d --name <container-name> -p <host-port>:<container-port> <image>
Step 6: Verify the Container
# Check container is running
docker ps
# Check specific container
docker ps | grep cluster
# Verify port mapping
docker port cluster
# Test the container
curl http://localhost:3001
🔍 Additional Verification
# Check container details
docker inspect cluster
# Check container logs
docker logs cluster
# Check container IP
docker inspect cluster | grep IPAddress
# Check port mapping details
docker inspect cluster | grep -A 5 "PortBindings"
# Test from external (if accessible)
curl http://stapp03:3001
🛠️ Troubleshooting
If Port 3001 is Already in Use:
# Check what's using port 3001
sudo ss -tulpn | grep 3001
sudo lsof -i :3001
# Stop the container using the port
docker stop <container-name>
docker rm <container-name>
# Or use a different port
docker run -d --name cluster -p 3002:80 nginx:alpine
If Container Fails to Start:
# Check container logs
docker logs cluster
# Remove and recreate
docker rm -f cluster
docker run -d --name cluster -p 3001:80 nginx:alpine
If Image Pull Fails:
# Check internet connectivity
ping -c 4 google.com
# Try pulling with different registry
docker pull docker.io/nginx:alpine
🔑 Key Points
| Parameter | Value | Description |
|---|---|---|
| Image | nginx:alpine |
Lightweight nginx image |
| Container Name | cluster |
Name of the container |
| Host Port | 3001 |
Port on the host machine |
| Container Port | 80 |
Port inside the container |
| Mapping Format | -p 3001:80 |
host-port:container-port |
✅ Task Summary
| Requirement | Status | Command Used |
|---|---|---|
| SSH to App Server 3 | ✅ | ssh banner@stapp03 |
| Switch to root | ✅ | sudo -i |
| Pull nginx:alpine image | ✅ | docker pull nginx:alpine |
Create container named cluster
|
✅ | docker run -d --name cluster |
| Map host port 3001 to container port 80 | ✅ | -p 3001:80 |
| Container in running state | ✅ |
docker ps shows Up status |
| Test successful | ✅ | curl http://localhost:3001 |
Top comments (0)