ImHost is a web server that simply responds the "host name" of the server at port 80.
Its main purpose is for testing and demonstration of load balancing and scaling of Docker containers.
We provide a Dockerfile for convenience. See the "Docker Compose with scale and round-robin" section for the full example using "--scale" option and Nginx as a load balancer as well.
$ # Build the image
$ docker build -t imhost https://github.com/KEINOS/imhost.git
**snip**
$ # Run the container (expose the port 80 to 8080)
$ docker run --rm -p 8080:80 imhost
**snip**
$ # Check the hostname
$ curl -sS http://localhost:8080/
Hello from host: f9536b7afae0
Here is an example of docker-compose.yml
that can:
- Scale-up
imhost
containers using--scale
option. - Load balancing using
nginx
.
$ # Run the containers and scale the imhost to 5 instances
docker compose up --scale imhost=5 --detach
**snip**
$ # Check the host names.
$ # Note that the host names are different each time because of
$ # the round-robin.
$ curl -sS http://localhost:8080
Hello from host: 2c80ea38d91a
$ curl -sS http://localhost:8080
Hello from host: 5fec68e38b9b
$ curl -sS http://localhost:8080
Hello from host: 353184aa84c0
version: '3'
services:
imhost:
build:
context: https://github.com/KEINOS/imhost.git
expose:
- "80"
restart: unless-stopped
loadbalancer:
image: nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "8080:80"
depends_on:
- imhost
restart: unless-stopped
user nginx;
worker_processes auto;
events {
worker_connections 1024;
}
http {
server {
listen 80;
location / {
proxy_pass http://imhost:80/;
}
}
}
- For the full example, see the example directory.