Container Until Healthy
An agent loop that builds your Docker image, starts the container, probes its health endpoint, and fixes the Dockerfile or config until it serves traffic.
Copy the Container Until Healthy loop
Stops when the image builds and the container answers its health check within the timeout, or after 8 iterations. Edit the settings block, then paste the whole prompt into your agent.
You are running the "Container Until Healthy" loop. Settings (edit before running): - Build command: docker build -t app-loop-test . - Run command: docker run -d --name app-loop-test -p 8080:8080 --env-file .env.example app-loop-test - Health check: GET http://localhost:8080/health returns 200 - Start-up timeout: 60 seconds - Max iterations: 8 Goal: the image builds and the container passes the health check within the timeout. Each iteration: 1. Run the build command. If it fails, read the failing step and fix it. 2. Run the container. Poll the health check every 5 seconds until it passes or the timeout ends. 3. If it fails, collect "docker ps -a" status for the container and the last 100 lines of "docker logs". 4. Identify the first error in the logs (missing file, wrong port, missing env var, permission denied, crash on boot) and make one fix. 5. Stop and remove the test container before the next iteration. Stop when: - The health check passes. Success. Leave the container stopped and removed. - You reach the max iteration count. Rules: - Only use example or dummy values for environment variables. Never copy real secrets into the Dockerfile, image layers, or logs. - Only stop and remove containers and images tagged app-loop-test. Do not prune or touch other containers, images, or volumes. - Do not run the container with --privileged or mount the Docker socket. - Keep the image non-root if it already is. Final report: the Dockerfile and config changes with reasons, final image size, and the start-up time you measured.
When this loop fits
- You are containerizing an app for the first time and the image builds but the container exits on start.
- A base image or runtime upgrade broke the container and the logs are not obvious.
- You want a slimmer or non-root image and need to confirm it still boots after each change.
What happens on each pass
The agent repeats these steps until the stop condition holds or it runs out of iterations.
- Build the image. Build with a throwaway tag and capture the build output.
- Start the container. Run it detached with the expected port mapping and environment, then wait for the start-up window.
- Probe health. Request the health endpoint and collect the container status and its recent logs.
- Fix one cause. Change the Dockerfile, entrypoint, or app config to address the first error in the logs.
- Clean up and repeat. Stop and remove the test container, then rebuild and probe again.
MCP servers for this loop
The 6 strongest of 763 matching servers, ranked by how closely they fit and then by trust score.
- 76Trust score 76 of 100, Good
kubernetes-mcp-server
by containers · Go
A Model Context Protocol (MCP) server for Kubernetes and OpenShift
RegistryLicenseQualityMaintenanceLicense: A. Apache-2.0 is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 15 days ago. - 74Trust score 74 of 100, Good
Kubernetes MCP server for diagnosis, resource management, GitOps, and RBAC-enforced operations.
RegistryLicenseQualityMaintenanceLicense: A. Apache-2.0 is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release yesterday. - 72Trust score 72 of 100, Good
Read-only Model Context Protocol MCP server enabling code-driven AI analysis of Kubernetes clusters.
RegistryLicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 28 days ago. - 68Trust score 68 of 100, Good
Docker MCP Server
by l337-org · Python
Manage Docker (containers, images, Compose, Swarm, registries) via the Docker SDK and CLI.
RegistryLicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 12 days ago. - 68Trust score 68 of 100, Good
Dockerhub
by pipeworx-io · JavaScript
Docker Hub MCP — wraps the Docker Hub v2 API (free, no auth required for public data)
RegistryRemoteLicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 10 days ago. - 68Trust score 68 of 100, Good
kitsune-mcp
by kaiser-data · Python
Hot-reload for MCP servers + mount any community server mid-session, Docker optional. No restarts.
RegistryLicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 20 days ago.
How to run this loop
- Connect the tools. Install a server the loop can use, for example kubernetes-mcp-server, or rely on your agent's built-in terminal and file access.
- Edit the settings block. Replace the example commands, targets, and limits with your project's own. Keep the iteration cap low on the first run.
- Paste it into an agent session. Start a fresh session in Claude Code, Cursor, or VS Code agent mode, in the repository root, and paste the prompt.
- Review before you merge. Read the final report and the diff. The loop leaves its work for you to review rather than shipping it.
Container Until Healthy questions
When does the Container Until Healthy loop stop?
It stops as soon as the image builds and the container answers its health check within the timeout. It also stops after 8 iterations by default, or earlier when the prompt's own stop rules say it is stuck, and then reports what changed and what is left. Change the cap in the settings block at the top of the prompt.
Do I need a Docker MCP server for this loop?
No. An agent with shell access can run docker commands directly. A Docker MCP server helps when your client has no terminal, or when you want the agent limited to container operations instead of a full shell.
Does this work with Docker Compose?
Yes. Swap the build and run commands for docker compose build and docker compose up -d, point the health check at the service you care about, and restrict cleanup to that compose project with docker compose down.