Skip to main content
Glama

docker_build

Build Docker images with step-by-step guidance for containerization workflows in development and deployment pipelines.

Instructions

Build a Docker image with guidance

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'docker_build' tool. It validates the image name, checks for a Dockerfile in the specified path, executes the 'docker build' command, and provides user-friendly success or error messages with next steps.
      async ({ image_name, tag, path }) => {
        // Validate image name
        if (!/^[a-z0-9][a-z0-9._-]*$/.test(image_name)) {
          return {
            content: [{
              type: "text",
              text: `Invalid image name: "${image_name}"
    
    Rules:
    - Must be lowercase
    - Must start with letter or number
    - Can contain: a-z, 0-9, ., -, _
    
    Examples: myapp, my-api, company.service`
            }]
          };
        }
    
        // Check Dockerfile exists
        try {
          await access(`${path}/Dockerfile`, constants.F_OK);
        } catch {
          return {
            content: [{
              type: "text",
              text: `No Dockerfile found in ${path}
    
    Use 'docker_analyze_project' tool to generate one.`
            }]
          };
        }
    
        const fullTag = `${image_name}:${tag}`;
        const result = await runCommand(`docker build -t ${fullTag} ${path}`, { timeout: 300000 });
    
        if (!result.success) {
          return {
            content: [{
              type: "text",
              text: `Build failed!\n\nError:\n${result.stderr || result.error}\n\nCommon fixes:\n- Check Dockerfile syntax\n- Ensure base image exists\n- Check file permissions`
            }]
          };
        }
    
        return {
          content: [{
            type: "text",
            text: `Successfully built: ${fullTag}
    
    NEXT STEPS:
    1. Test locally:
       docker run -p 8080:8080 ${fullTag}
    
    2. View running containers:
       docker ps
    
    3. Push to registry:
       - Docker Hub:  docker push ${fullTag}
       - GHCR:        docker tag ${fullTag} ghcr.io/OWNER/${fullTag}
                      docker push ghcr.io/OWNER/${fullTag}`
          }]
        };
      }
  • JSON schema defining the input parameters for the 'docker_build' tool: image_name (required string), tag (string, default 'latest'), path (string, default '.').
    {
      image_name: { type: "string", description: "Name for the image (lowercase)" },
      tag: { type: "string", description: "Image tag", default: "latest" },
      path: { type: "string", description: "Build context path", default: "." }
    },
  • src/index.js:378-449 (registration)
    MCP server registration of the 'docker_build' tool, including name, description, input schema, and handler function reference.
    server.tool(
      "docker_build",
      "Build a Docker image with guidance",
      {
        image_name: { type: "string", description: "Name for the image (lowercase)" },
        tag: { type: "string", description: "Image tag", default: "latest" },
        path: { type: "string", description: "Build context path", default: "." }
      },
      async ({ image_name, tag, path }) => {
        // Validate image name
        if (!/^[a-z0-9][a-z0-9._-]*$/.test(image_name)) {
          return {
            content: [{
              type: "text",
              text: `Invalid image name: "${image_name}"
    
    Rules:
    - Must be lowercase
    - Must start with letter or number
    - Can contain: a-z, 0-9, ., -, _
    
    Examples: myapp, my-api, company.service`
            }]
          };
        }
    
        // Check Dockerfile exists
        try {
          await access(`${path}/Dockerfile`, constants.F_OK);
        } catch {
          return {
            content: [{
              type: "text",
              text: `No Dockerfile found in ${path}
    
    Use 'docker_analyze_project' tool to generate one.`
            }]
          };
        }
    
        const fullTag = `${image_name}:${tag}`;
        const result = await runCommand(`docker build -t ${fullTag} ${path}`, { timeout: 300000 });
    
        if (!result.success) {
          return {
            content: [{
              type: "text",
              text: `Build failed!\n\nError:\n${result.stderr || result.error}\n\nCommon fixes:\n- Check Dockerfile syntax\n- Ensure base image exists\n- Check file permissions`
            }]
          };
        }
    
        return {
          content: [{
            type: "text",
            text: `Successfully built: ${fullTag}
    
    NEXT STEPS:
    1. Test locally:
       docker run -p 8080:8080 ${fullTag}
    
    2. View running containers:
       docker ps
    
    3. Push to registry:
       - Docker Hub:  docker push ${fullTag}
       - GHCR:        docker tag ${fullTag} ghcr.io/OWNER/${fullTag}
                      docker push ghcr.io/OWNER/${fullTag}`
          }]
        };
      }
    );
  • Helper function 'runCommand' used by the docker_build handler to safely execute shell commands like 'docker build', with timeout and error handling.
    async function runCommand(cmd, options = {}) {
      try {
        const { stdout, stderr } = await execAsync(cmd, { timeout: 30000, ...options });
        return { success: true, stdout: stdout.trim(), stderr: stderr.trim() };
      } catch (error) {
        return { success: false, error: error.message, stdout: error.stdout?.trim(), stderr: error.stderr?.trim() };
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states 'with guidance,' which is ambiguous. It doesn't disclose behavioral traits like whether it's interactive, requires authentication, has side effects (e.g., creating local images), or handles errors. This leaves the agent uncertain about how the tool operates beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action. However, 'with guidance' adds ambiguity without clear value, slightly reducing effectiveness. Overall, it's appropriately sized with minimal waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a vague description, this is incomplete for a tool that likely involves complex Docker operations. The description doesn't explain what 'guidance' entails, expected outcomes, or error handling, leaving significant gaps for the agent to infer behavior.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description doesn't add param info, which is fine here. Baseline is 4 since there are no parameters to explain, and the schema fully covers this aspect.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Build a Docker image with guidance' clearly states the action (build) and resource (Docker image), but it's vague about what 'with guidance' means—whether it's interactive help, step-by-step instructions, or automated assistance. It doesn't distinguish from siblings like docker_analyze_project or ghcr_push, which might involve similar Docker-related tasks.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives is provided. It doesn't mention prerequisites (e.g., Docker setup), context (e.g., after writing a Dockerfile), or exclusions. The description implies it's for building images, but without comparison to siblings, the agent might struggle to choose between this and other Docker tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rideRTD/RTD-DevOps'

If you have feedback or need assistance with the MCP directory API, please join our Discord server