Skip to main content
Glama

docker_build

Build a Docker image from a Dockerfile with configurable context, tag, build arguments, multi-stage target, cache usage, base image pulling, and platform.

Instructions

Build a Docker image from a Dockerfile

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextNoBuild context path (default: current directory)
dockerfileNoPath to Dockerfile (relative to context)
tagNoTag for the built image (e.g., myapp:latest)
build_argsNoBuild arguments as key-value pairs
targetNoTarget stage for multi-stage builds
no_cacheNoDo not use cache when building
pullNoAlways attempt to pull newer version of base image
platformNoTarget platform (e.g., linux/amd64, linux/arm64)

Implementation Reference

  • Core handler function that builds a Docker image. Constructs a 'docker build' CLI command from arguments and executes it via executeDockerCommand.
    async buildImage(args: DockerBuildArgs): Promise<ToolResult> {
      const { 
        context = '.', 
        dockerfile, 
        tag, 
        build_args, 
        target, 
        no_cache, 
        pull, 
        quiet,
        squash,
        platform,
        progress = 'auto',
        secret,
        ssh,
        network
      } = args;
    
      // Validate context exists
      const contextPath = this.workspaceService.resolvePath(context);
      try {
        await fs.access(contextPath);
      } catch {
        throw new Error(`Build context not found: ${contextPath}`);
      }
    
      let command = `docker build ${this.quotePath(contextPath)}`;
      
      if (dockerfile) command += ` -f ${this.quotePath(dockerfile)}`;
      if (tag) command += ` -t ${tag}`;
      if (target) command += ` --target ${target}`;
      if (no_cache) command += ' --no-cache';
      if (pull) command += ' --pull';
      if (quiet) command += ' --quiet';
      if (squash) command += ' --squash';
      if (platform) command += ` --platform ${platform}`;
      if (progress) command += ` --progress ${progress}`;
      if (network) command += ` --network ${network}`;
      
      if (build_args) {
        for (const [key, value] of Object.entries(build_args)) {
          command += ` --build-arg ${key}=${value}`;
        }
      }
      
      if (secret) {
        secret.forEach(s => command += ` --secret ${s}`);
      }
      
      if (ssh) command += ` --ssh ${ssh}`;
    
      try {
        return await this.executeDockerCommand(command, { cwd: this.getCurrentWorkspace() }, this.buildTimeout);
      } catch (error: any) {
        throw new Error(`Docker build failed: ${error.message}`);
      }
    }
  • TypeScript interface defining the input schema/arguments for the docker_build tool.
    export interface DockerBuildArgs {
      context?: string;
      dockerfile?: string;
      tag?: string;
      build_args?: Record<string, string>;
      target?: string;
      no_cache?: boolean;
      pull?: boolean;
      quiet?: boolean;
      squash?: boolean;
      platform?: string;
      progress?: 'auto' | 'plain' | 'tty';
      secret?: string[];
      ssh?: string;
      network?: string;
    }
  • MCP tool definition/registration schema for docker_build, specifying name, description, and input JSON schema.
    {
      name: 'docker_build',
      description: 'Build a Docker image from a Dockerfile',
      inputSchema: {
        type: 'object',
        properties: {
          context: { type: 'string', description: 'Build context path (default: current directory)' },
          dockerfile: { type: 'string', description: 'Path to Dockerfile (relative to context)' },
          tag: { type: 'string', description: 'Tag for the built image (e.g., myapp:latest)' },
          build_args: { type: 'object', description: 'Build arguments as key-value pairs' },
          target: { type: 'string', description: 'Target stage for multi-stage builds' },
          no_cache: { type: 'boolean', description: 'Do not use cache when building' },
          pull: { type: 'boolean', description: 'Always attempt to pull newer version of base image' },
          platform: { type: 'string', description: 'Target platform (e.g., linux/amd64, linux/arm64)' },
        },
      },
    },
  • src/index.ts:205-206 (registration)
    Registration in the main server switch statement that routes 'docker_build' tool calls to DockerService.buildImage().
    case 'docker_build':
      return await this.dockerService.buildImage(args as DockerBuildArgs);
  • Helper/focused wrapper method that delegates to buildImage with a subset of parameters.
    async dockerImageBuild(args: {
      context?: string;
      dockerfile?: string;
      tag?: string;
      build_args?: Record<string, string>;
      no_cache?: boolean;
    }): Promise<ToolResult> {
      const buildArgs: DockerBuildArgs = {
        context: args.context,
        dockerfile: args.dockerfile,
        tag: args.tag,
        build_args: args.build_args,
        no_cache: args.no_cache
      };
      return this.buildImage(buildArgs);
    }
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 the basic purpose. It fails to disclose key behavioral traits such as Docker daemon requirement, caching behavior, or that it may pull base images. The description adds no value beyond the tool's name.

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 concise sentence that front-loads the tool's purpose. It is appropriately sized, though could be slightly more informative without losing conciseness.

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

Completeness3/5

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

Given 8 parameters (all documented), no output schema, and no annotations, the description is minimally adequate but does not mention return values (e.g., image ID) or side effects. It relies heavily on the schema for completeness.

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

Parameters3/5

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

Schema description coverage is 100%, so baseline is 3. The description adds no additional meaning beyond the schema; it does not explain the build_args object format or the target stage concept.

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

Purpose5/5

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

The description 'Build a Docker image from a Dockerfile' uses a specific verb-resource combination that clearly identifies the tool's action and distinguishes it from siblings like docker_run (run containers) or docker_images (list images).

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?

The description provides no guidance on when to use this tool versus alternatives like docker_compose, which can also build images. No exclusions or prerequisites are mentioned.

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/agentics-ai/code-mcp'

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