A simple HTTP server to show container's hostname & IP & Rancher logo
1.8K
default using TCP port 80.
Quick Demo:
docker run -it --rm --name=rancher-web-demo -p 8080:80 dyadin/rancher-demo:latest
K8s Demo yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: rancher-demo
labels:
app: rancher-demo
spec:
replicas: 3
selector:
matchLabels:
app: rancher-demo
template:
metadata:
labels:
app: rancher-demo
spec:
containers:
- name: rancher-nginx
image: dyadin/rancher-demo
ports:
- containerPort: 80
env:
- name: hostinfo
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
Example:

Dockfile to build the image:
# cat Dockerfile
FROM rancher/nginx:1.17.4-alpine
COPY start.sh favicon.ico rancher.png /usr/share/nginx/html/
CMD ["/usr/share/nginx/html/start.sh" ]
start.sh startup shell script
cat start.sh
#!/bin/sh
echo "
<html>
<head>
<title>Rancher HTTP Server Demo</title>
</head>
<body>
<h2>Hello, this web-page is served by: `tail -1 /etc/hosts|awk '{print $2}'`</h2>
<h2>Current container's private IP is: `tail -1 /etc/hosts|awk '{print $1}'`</h2>
<h2>Current container is running on host: "$hostinfo"</h2>
<img src="rancher.png">
</body>
</html>" > /usr/share/nginx/html/index.html && \
nginx -g "daemon off;"
Content type
Image
Digest
Size
8.3 MB
Last updated
over 6 years ago
docker pull dyadin/rancher-demo