Skip to main content
Glama

Run container

run_container

Start a new container with specified image, ports, volumes, and environment variables. Configure container settings and run applications in isolated environments.

Instructions

Run a new container.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageYesContainer image
nameNoOptional name
detachNoRun in background
portsNoPort mappings (e.g., ['8080:80'])
envNoEnvironment variables (KEY=VAL)
volumesNoVolumes (e.g., ['/host:/container'])

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function that implements the core logic of the 'run_container' tool by building and executing a 'podman run' command based on input parameters.
    async def run_container(self, args: Dict[str, Any]) -> Dict[str, Any]:
        image = args.get("image")
        name = args.get("name")
        detach = args.get("detach", True)
        ports = args.get("ports", [])
        env = args.get("env", [])
        volumes = args.get("volumes", [])
        
        cmd_args = ["run"]
        if detach:
            cmd_args.append("-d")
        if name:
            cmd_args.extend(["--name", name])
        for p in ports:
            cmd_args.extend(["-p", p])
        for e in env:
            cmd_args.extend(["-e", e])
        for v in volumes:
            cmd_args.extend(["-v", v])
        cmd_args.append(image)
        
        result = run_podman(cmd_args)
        return {"output": f"Started container: {result['stdout']}" if result["success"] else f"Error: {result['stderr']}"}
  • The input schema for the 'run_container' tool, defining parameters such as image (required), name, detach, ports, env, and volumes.
        name="run_container",
        description="Run a new container",
        inputSchema={
            "type": "object",
            "properties": {
                "image": {
                    "type": "string",
                    "description": "Container image"
                },
                "name": {
                    "type": "string",
                    "description": "Optional container name"
                },
                "detach": {
                    "type": "boolean",
                    "description": "Run in background",
                    "default": True
                },
                "ports": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Port mappings (e.g., ['8080:80'])",
                    "default": []
                },
                "env": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Environment variables (KEY=VAL)",
                    "default": []
                },
                "volumes": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Volumes (e.g., ['/host:/container'])",
                    "default": []
                }
            },
            "required": ["image"]
        }
    ),
  • main_b.py:459-472 (registration)
    Registration of the 'run_container' tool handler in the tool_handlers dictionary used in handle_tools_call.
    tool_handlers = {
        "list_containers": self.list_containers,
        "container_info": self.container_info,
        "start_container": self.start_container,
        "stop_container": self.stop_container,
        "restart_container": self.restart_container,
        "container_logs": self.container_logs,
        "run_container": self.run_container,
        "remove_container": self.remove_container,
        "exec_container": self.exec_container,
        "list_images": self.list_images,
        "pull_image": self.pull_image,
        "container_stats": self.container_stats,
    }
  • main.py:200-223 (handler)
    Alternative implementation of the 'run_container' tool using the @mcp.tool decorator, which also handles schema and registration.
    @mcp.tool(title="Run container", description="Run a new container.")
    def run_container(
        image: str = Field(..., description="Container image"),
        name: str = Field(None, description="Optional name"),
        detach: bool = Field(True, description="Run in background"),
        ports: List[str] = Field(default_factory=list, description="Port mappings (e.g., ['8080:80'])"),
        env: List[str] = Field(default_factory=list, description="Environment variables (KEY=VAL)"),
        volumes: List[str] = Field(default_factory=list, description="Volumes (e.g., ['/host:/container'])"),
    ) -> str:
        args = ["run"]
        if detach:
            args.append("-d")
        if name:
            args.extend(["--name", name])
        for p in ports:
            args.extend(["-p", p])
        for e in env:
            args.extend(["-e", e])
        for v in volumes:
            args.extend(["-v", v])
        args.append(image)
    
        result = run_podman(args)
        return f"Started container: {result['stdout']}" if result["success"] else f"Error: {result['stderr']}"
  • main.py:379-402 (handler)
    Duplicate implementation of the 'run_container' tool in main.py using @mcp.tool decorator.
    @mcp.tool(title="Run container", description="Run a new container.")
    def run_container(
        image: str = Field(..., description="Container image"),
        name: str = Field(None, description="Optional name"),
        detach: bool = Field(True, description="Run in background"),
        ports: List[str] = Field(default_factory=list, description="Port mappings (e.g., ['8080:80'])"),
        env: List[str] = Field(default_factory=list, description="Environment variables (KEY=VAL)"),
        volumes: List[str] = Field(default_factory=list, description="Volumes (e.g., ['/host:/container'])"),
    ) -> str:
        args = ["run"]
        if detach:
            args.append("-d")
        if name:
            args.extend(["--name", name])
        for p in ports:
            args.extend(["-p", p])
        for e in env:
            args.extend(["-e", e])
        for v in volumes:
            args.extend(["-v", v])
        args.append(image)
    
        result = run_podman(args)
        return f"Started container: {result['stdout']}" if result["success"] else f"Error: {result['stderr']}"
Behavior2/5

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

No annotations are provided, so the description carries full burden. 'Run a new container' implies a creation/mutation operation, but it doesn't disclose behavioral traits like whether it requires specific permissions, how it handles errors, if it's idempotent, what happens on conflicts (e.g., duplicate names), or the expected output format. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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

Conciseness5/5

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

The description is extremely concise with a single sentence 'Run a new container.' It's front-loaded and wastes no words, though this brevity contributes to gaps in other dimensions. Every word earns its place by stating the core action.

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 the tool has an output schema (which covers return values), 100% schema description coverage, and no annotations, the description is minimally complete but lacks context for a mutation tool. It doesn't address prerequisites, side effects, or error handling, which are important for an agent to use it correctly despite the structured data.

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 the schema already documents all 6 parameters with clear descriptions and examples (e.g., for ports, volumes). The description adds no additional meaning beyond what the schema provides, such as explaining parameter interactions or defaults. Baseline 3 is appropriate when the schema does the heavy lifting.

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 'Run a new container' clearly states the action (run) and resource (container), but it's vague about scope and doesn't distinguish from siblings like 'start_container' (which likely starts existing containers) or 'exec_container' (which executes commands in running containers). It specifies 'new' which helps somewhat, but lacks detail about what 'run' entails compared to alternatives.

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 guidance is provided on when to use this tool versus alternatives. With siblings like 'start_container', 'restart_container', and 'exec_container', the description doesn't clarify that this is for creating and launching new containers from images, not managing existing ones. This leaves the agent to infer usage from context alone.

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/kunwarmahen/podman-mcp-server'

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