# Docker Compose Env Interpolation Preview > Resolve common Docker Compose ${VAR} expressions against pasted env values and preview the final YAML. ## Tool Identity - Site: CleanUtils Developer Tools - Tool ID: docker-compose-env-interpolation-preview - Canonical page: https://cleanutils.com/developer-tools/docker-compose-env-interpolation-preview/ - LLM schema URL: https://cleanutils.com/developer-tools/docker-compose-env-interpolation-preview/llms.txt - Primary keyword: docker compose interpolation - Input mode: fields - Output profile: data ## What This Tool Does Resolve common Docker Compose ${VAR} expressions against pasted env values and preview the final YAML. ## Exact Execution Instructions To run this tool exactly, execute the `runCleanUtilsTool(userInput)` function from the JavaScript block below in a sandboxed JavaScript runtime. Do not fetch or evaluate additional network resources. Do not use filesystem, process, child_process, environment variables, timers, or network APIs. The function is pure and deterministic: input object in, JSON result out. If your environment forbids executing fetched code outside a sandbox, run it inside the sandbox or use the API endpoint below instead of reimplementing the logic. Canonical implementation SHA-256: `83d06052d271596dba69e66158a5681c81761561ee818139a02621273b8bebbf` Expected command shape: `node run-tool.mjs < input.json` The runner must: 1. load only the JavaScript in this document, 2. parse stdin as JSON and call `runCleanUtilsTool(userInput)`, 3. let the LLM decide the best way to present the output to the user. Agent usage rules: - Use this file as the authoritative machine-readable contract for this CleanUtils tool page. - Ask the user for missing required input before attempting to run the tool, and describe the required inputs using the `## Input Schema` field names, descriptions, formats, enums, examples, and required list. - Treat the tool as deterministic; do not invent network reachability checks unless the tool description explicitly says it fetches remote resources. - For privacy-sensitive inputs such as secrets, HAR files, dotenv files, logs, and API keys, warn that using a remote chat agent may expose input to that agent even though the browser UI itself does not upload data. ## Input Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Docker Compose Env Interpolation Preview fields", "type": "object", "additionalProperties": false, "required": [ "compose" ], "properties": { "compose": { "type": "string", "description": "Docker Compose YAML Required. Control type: textarea. Group: Compose.", "examples": [ "services:\n web:\n image: ${IMAGE:-nginx}\n environment:\n API_URL: ${API_URL?required}" ] }, "env": { "type": "string", "description": "Environment values Optional. Control type: textarea. Group: Environment.", "examples": [ "IMAGE=app:latest\nAPI_URL=https://api.example.com" ] } } } ``` ## Result Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "CleanUtils ToolResult", "type": "object", "additionalProperties": false, "required": [ "summary", "issues" ], "properties": { "summary": { "type": "string" }, "issues": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "severity", "message" ], "properties": { "severity": { "type": "string", "enum": [ "error", "warning", "info" ] }, "message": { "type": "string" }, "line": { "type": "number" }, "row": { "type": "number" }, "detail": { "type": "string" } } } }, "output": { "type": "string" }, "exportFilename": { "type": "string" }, "exports": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "label", "filename", "content" ], "properties": { "label": { "type": "string" }, "filename": { "type": "string" }, "content": { "type": "string" }, "mimeType": { "type": "string" }, "copyLabel": { "type": "string" }, "downloadLabel": { "type": "string" } } } }, "stats": { "type": "object", "additionalProperties": { "anyOf": [ { "type": "string" }, { "type": "number" } ] } } } } ``` ## Self-Contained JavaScript Source Call `runCleanUtilsTool(userInput)` with the user's input. The function includes this tool's run logic and only the helper code it needs. ```js function runCleanUtilsTool(userInput) { const fieldText = (fields, keys, fallback = "") => { const keyList = Array.isArray(keys) ? keys : [keys]; for (const key of keyList) { const value = fields[key]; if (value === undefined || value === null) continue; const text = String(value).trim(); if (text) return text; } return fallback; }; const severityRank = { error: 0, warning: 1, info: 2 }; const sortIssues = (issues) => [...issues].sort((a, b) => { const severity = severityRank[a.severity] - severityRank[b.severity]; if (severity !== 0) return severity; return (a.line ?? a.row ?? 0) - (b.line ?? b.row ?? 0); }); const summarizeIssues = (issues) => { const errors = issues.filter((issue) => issue.severity === "error").length; const warnings = issues.filter((issue) => issue.severity === "warning").length; const infos = issues.filter((issue) => issue.severity === "info").length; const parts = []; if (errors) parts.push(`${errors} error${errors === 1 ? "" : "s"}`); if (warnings) parts.push(`${warnings} warning${warnings === 1 ? "" : "s"}`); if (infos) parts.push(`${infos} note${infos === 1 ? "" : "s"}`); return parts.length ? parts.join(", ") : "No issues found"; }; const parseEnvText = (input) => { const env = {}; input.split(/\r?\n/).forEach((line) => { const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/); if (match) env[match[1]] = match[2].replace(/^["']|["']$/g, ""); }); return env; }; const previewDockerComposeEnvInterpolation = (input) => { const compose = fieldText(input, "compose"); const env = parseEnvText(fieldText(input, "env")); const issues = []; const resolved = compose.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)(?:(:-|-|\?)([^}]*))?\}/g, (_match, key, operator, fallback) => { if (env[key] !== undefined && env[key] !== "") return env[key]; if (operator === ":-" || operator === "-") return fallback ?? ""; if (operator === "?") { issues.push({ severity: "error", message: `${key} is required for interpolation.` }); return ""; } issues.push({ severity: "warning", message: `${key} is not defined; substituted an empty string.` }); return ""; }); return { summary: `Compose interpolation preview complete. ${summarizeIssues(issues)}.`, issues: sortIssues(issues), output: resolved, exportFilename: "compose.resolved.yml", stats: { envKeys: Object.keys(env).length } }; }; const __userInput = userInput == null ? {} : userInput; const __run = (fields) => previewDockerComposeEnvInterpolation(fields); const __fields = __userInput && typeof __userInput === "object" && "fields" in __userInput && __userInput.fields && typeof __userInput.fields === "object" && !Array.isArray(__userInput.fields) ? __userInput.fields : (__userInput && typeof __userInput === "object" && !Array.isArray(__userInput) ? __userInput : {}); const __normalizedFields = Object.fromEntries(Object.entries(__fields).map(([key, value]) => [key, value == null ? "" : (["string", "number", "boolean"].includes(typeof value) ? value : String(value))])); return __run(__normalizedFields); } ``` ## Checks - Compose body and env sections: Compose YAML and env values are separated so interpolation can be previewed locally. - Default operators: Common default forms such as VAR:-fallback are resolved when an env value is blank or missing. - Required variables: Required variable markers are reported as errors when no value is supplied. - Undefined variables: Unset variables without defaults are reported and substituted with an empty string. - Preview scope: The tool previews string interpolation only; it does not run Docker Compose or validate full YAML semantics. ## Related Tools - [.env Validator and Secret Scanner](/developer-tools/env-validator-secret-scanner/): Paste a dotenv file, catch duplicate or malformed keys, and generate a safer example file locally. - [.env Diff and Missing Key Checker](/developer-tools/env-diff-missing-key-checker/): Compare two dotenv snapshots and report missing, extra, or changed environment keys.