hashicorp/demo-webapp本镜像是 Nomad 101 培训课程配套的示例 Web 应用容器化封装,基于轻量级基础镜像构建,提供简化的 HTTP 服务能力,用于演示容器化应用在 Nomad 调度系统中的部署、运行及管理流程。
作为 Nomad 101 培训课程的核心实践工具,用于辅助学员理解容器化应用的生命周期管理,包括:
本镜像需从 Nomad 101 培训课程指定的仓库获取(如课程内部 Registry 或本地构建)。假设镜像标签为 nomad101-sample-webapp:latest。
通过 docker run 命令启动容器,验证应用基础功能:
bash# 基本运行(默认配置) docker run -d --name nomad101-sample-webapp -p 8080:8080 nomad101-sample-webapp:latest # 验证服务可用性(访问默认 HTTP 接口) curl http://localhost:8080 # 预期输出:默认响应消息(如 "Nomad 101 Sample Web App Running")
通过环境变量调整服务行为(详见 4.3 环境变量说明):
bash# 自定义端口、响应消息和健康检查路径 docker run -d --name nomad101-sample-webapp \ -p 9000:9000 \ -e PORT=9000 \ -e MESSAGE="Hello from Nomad 101 Training" \ -e HEALTHCHECK_PATH="/health" \ nomad101-sample-webapp:latest # 验证自定义配置 curl http://localhost:9000 # 输出自定义 MESSAGE curl http://localhost:9000/health # 验证健康检查接口(返回 HTTP 200)
| 环境变量名 | 描述 | 默认值 | 示例值 |
|---|---|---|---|
PORT | 服务监听端口 | 8080 | 9000 |
MESSAGE | HTTP 根路径响应消息 | "Nomad 101 Sample Web App Running" | "Custom Training Message" |
HEALTHCHECK_PATH | 健康检查接口路径 | "/health" | "/status" |
LOG_LEVEL | 日志级别(debug/info/warn/error) | "info" | "debug" |
应用默认内置健康检查接口,可通过以下方式验证:
bash# 检查容器健康状态(Docker 原生健康检查) docker inspect --format='{{.State.Health.Status}}' nomad101-sample-webapp # 预期输出:healthy # 直接访问健康检查接口 curl -I http://localhost:8080/health # 预期响应:HTTP/1.1 200 OK
docker run 命令bash# 启动服务并映射宿主机端口 8080,设置自定义消息 docker run -d \ --name nomad101-webapp-demo \ -p 8080:8080 \ -e MESSAGE="Nomad 101 Training - Docker Run Demo" \ --health-cmd "curl -f http://localhost:8080/health || exit 1" \ --health-interval 5s \ --health-timeout 2s \ --health-retries 3 \ nomad101-sample-webapp:latest
适用于多容器协同演示场景(如配合 Nomad 客户端容器):
yaml# docker-compose.yml version: '3.8' services: nomad101-webapp: image: nomad101-sample-webapp:latest container_name: nomad101-webapp ports: - "8080:8080" environment: - PORT=8080 - MESSAGE="Nomad 101 Compose Demo" - LOG_LEVEL=debug healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/health"] interval: 5s timeout: 2s retries: 3 restart: unless-stopped
启动命令:
bashdocker-compose up -d
cpu=100m, memory=64Mi),符合培训环境资源规划。docker rm -f 或 Nomad 任务销毁命令清理容器,避免占用环境资源。manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务