Operations 9 min read

How to Manage Docker Containers with Natural Language Using MCP Docker Server

This guide explains how the open‑source Model Context Protocol (MCP) enables natural‑language control of Docker containers, walks through environment setup, Spring AI integration, client project configuration, and demonstrates a full execution log showing automated image pulling, port mapping, volume mounting, and container startup.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
How to Manage Docker Containers with Natural Language Using MCP Docker Server

MCP (Model Context Protocol) is an innovative open‑source protocol designed to dramatically simplify AI application development by providing a standardized communication interface that bridges AI models and application contexts.

MCP Docker Server Usage Guide

With the growing popularity of containerization, Docker management often requires many commands and configurations. The MCP Docker Server is a revolutionary tool that lets you manage Docker containers using natural language, lowering the entry barrier.

By describing actions in everyday language, such as "Start an Nginx container and map it to port 8080, mounting a specific directory for static files," the AI automatically performs all necessary deployment steps, including:

Pulling the appropriate image

Configuring port mapping

Setting up directory mounts

Starting and managing the container

This approach streamlines Docker usage, improves team efficiency, and reduces human error, benefiting both Docker beginners and experienced operators.

Spring AI and Docker Integration

Spring AI offers robust MCP integration, allowing developers to easily embed AI capabilities into Docker container management.

Environment Preparation

Install

uv
<code># The author uses macOS; on Windows, search for installation instructions
brew install uv
</code>

Download the

mcp-docker-server

plugin

<code>git clone https://github.com/ckreiling/mcp-server-docker.git
</code>

Create Client Project

First, add the required dependencies to your project:

<code>&lt;dependencyManagement&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.ai&lt;/groupId&gt;
            &lt;artifactId&gt;spring-ai-bom&lt;/artifactId&gt;
            &lt;version&gt;1.0.0-M5&lt;/version&gt;
            &lt;type&gt;pom&lt;/type&gt;
            &lt;scope&gt;import&lt;/scope&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/dependencyManagement&gt;

&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.ai&lt;/groupId&gt;
        &lt;artifactId&gt;spring-ai-openai-spring-boot-starter&lt;/artifactId&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.experimental&lt;/groupId&gt;
        &lt;artifactId&gt;spring-ai-mcp&lt;/artifactId&gt;
        &lt;version&gt;0.4.1&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;
</code>

Configuration File

The example uses the DeepSeek v3 model. Add the following to

application.properties

:

<code>spring.ai.openai.chat.options.model=deepseek-chat
spring.ai.openai.base-url=https://api.deepseek.com
spring.ai.openai.api-key=sk-XXX
</code>

MCP Docker Client Implementation

Below is a sample implementation that uses Spring AI and MCP to manage Docker containers:

<code>@Bean
public CommandLineRunner dockerCommands(ChatClient.Builder chatClientBuilder,
                                           List&lt;McpFunctionCallback&gt; functionCallbacks,
                                           ConfigurableApplicationContext context) {
    return args -> {
        var chatClient = chatClientBuilder
                .defaultFunctions(functionCallbacks.toArray(new McpFunctionCallback[0]))
                .build();
        // Example: manage Docker container with natural language
        String command = "启动一个 Nginx 容器并映射到 8888 端口 并挂载 /Users/lengleng/work/open/pig-ui/docker/dist 的静态页面";
        System.out.println("执行命令: " + command);
        System.out.println("AI 响应: " + chatClient.prompt(command).call().content());
        context.close();
    };
}

@Bean
public List&lt;McpFunctionCallback&gt; functionCallbacks(McpSyncClient mcpClient) {
    return mcpClient.listTools(null)
            .tools()
            .stream()
            .map(tool -> new McpFunctionCallback(mcpClient, tool))
            .toList();
}

@Bean(destroyMethod = "close")
public McpSyncClient mcpClient() {
    // Configure Docker MCP server, pointing to the mcp-server-docker plugin directory
    var dockerParams = ServerParameters.builder("uv")
            .args("--directory", "/Users/lengleng/Downloads/mcp-server-docker", "run", "mcp-server-docker")
            .build();
    var mcpClient = McpClient.using(new StdioClientTransport(dockerParams))
            .requestTimeout(Duration.ofSeconds(30))
            .sync();
    var init = mcpClient.initialize();
    System.out.println("Docker MCP service initialization status: " + init);
    return mcpClient;
}
</code>

Execution Log Example

The following shows a complete execution process, demonstrating how natural‑language commands manage Docker containers:

<code># 1. Execute natural language command
执行命令: 启动一个 Nginx 容器并映射到 8888 端口,并挂载 /Users/lengleng/work/open/pig-ui/docker/dist 的静态页面

# 2. System checks existing containers
发现冲突: 容器名称 "/nginx_container" 已被容器 "3f20f2720263..." 使用
状态: 系统自动处理冲突,移除旧容器

# 3. Create new container
容器ID: db72b87c2069...
容器名称: nginx_container
状态: 创建成功

# 4. Start container
状态: 运行中
端口映射: 80 -> 8888
目录挂载: /Users/lengleng/work/open/pig-ui/docker/dist -> /usr/share/nginx/html

# 5. Final result
✅ Nginx 容器成功启动
✅ 端口 8888 成功映射
✅ 静态文件目录成功挂载
</code>

From this log we can see that the MCP Docker Server:

Intelligently understands natural‑language commands

Automatically resolves container name conflicts

Correctly configures port mappings and volume mounts

Completes container creation and startup

This automation greatly simplifies Docker container management, allowing even complex operations to be performed with simple natural‑language instructions.

DockerMCPSpring AIContainer ManagementNatural Language
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.