feat(mcp): add MCP-optimized Docker image configuration and guide

This commit is contained in:
Daoud AbdelMonem Faleh 2026-03-05 02:17:26 +01:00
commit f5ebbdfc4b
3 changed files with 121 additions and 1 deletions

49
Dockerfile.mcp Normal file
View file

@ -0,0 +1,49 @@
# Stage 1: Build the dive binary
FROM golang:1.24-alpine AS builder
WORKDIR /src
# Pre-copy/cache go.mod for pre-downloading dependencies
COPY go.mod go.sum ./
RUN go mod download
# Explicitly copy required source directories to bypass .dockerignore exclusions
COPY cmd/ ./cmd/
COPY dive/ ./dive/
COPY internal/ ./internal/
# Build the binary with standard LDFlags for versioning
RUN go build -ldflags "-s -w -X main.version=v$(cat VERSION 2>/dev/null || echo '0.0.0-mcp')" -o /usr/local/bin/dive ./cmd/dive
# Stage 2: Final image
FROM alpine:3.21
# Install Docker CLI for engine-based analysis
# Using 28.0.0 as the default project standard
ARG DOCKER_CLI_VERSION=28.0.0
RUN apk add --no-cache ca-certificates wget tar && \
wget -O- https://download.docker.com/linux/static/stable/$(uname -m)/docker-${DOCKER_CLI_VERSION}.tgz | \
tar -xzf - docker/docker --strip-component=1 -C /usr/local/bin && \
apk del wget tar
# Copy the dive binary from builder
COPY --from=builder /usr/local/bin/dive /usr/local/bin/dive
# Metadata
LABEL org.opencontainers.image.title="Dive MCP Server"
LABEL org.opencontainers.image.description="Docker image explorer with MCP support (stdio, sse, streamable-http)"
LABEL org.opencontainers.image.source="https://github.com/wagoodman/dive"
LABEL maintainer="antholoj"
# Expose default port for MCP HTTP/SSE/Streamable transports
EXPOSE 8080
# Default environment for MCP
ENV DIVE_MCP_HOST=0.0.0.0
ENV DIVE_MCP_PORT=8080
# The entrypoint allows for standard 'dive' commands or 'dive mcp'
ENTRYPOINT ["/usr/local/bin/dive"]
# Default to help if no arguments are provided
CMD ["--help"]

View file

@ -0,0 +1,9 @@
# This file overrides the default .dockerignore for the MCP build.
# We leave it mostly empty to ensure all source code (cmd, dive, internal)
# is included in the build context.
.git
.tmp
.tool
snapshot/
dist/

View file

@ -66,7 +66,69 @@ dive mcp --transport sse --port 8080
---
## 3. Connecting MCP Clients
## 3. Using the Pre-built Docker Image
For a hassle-free setup, you can use the official **Dive MCP** image from Docker Hub. This image supports the classic Dive UI, CI mode, and all MCP transport protocols.
### Pull the Image
```bash
docker pull antholoj/dive-mcp:latest
```
### Building the Image Locally
If you want to build this specific MCP image yourself (e.g., to include local changes), use the following command. Note that this uses a dedicated ignore file (`Dockerfile.mcp.dockerignore`) to bypass the project's default restrictions on source directories:
```bash
# Build the MCP-optimized image
DOCKER_BUILDKIT=1 docker build -f Dockerfile.mcp -t antholoj/dive-mcp:latest .
```
### Running in Different Modes
#### A. Classic UI / CLI
To analyze an image using the standard interactive UI:
```bash
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
antholoj/dive-mcp:latest <your-image-tag>
```
#### B. CI Mode
To run an automated efficiency check:
```bash
docker run --rm -e CI=true \
-v /var/run/docker.sock:/var/run/docker.sock \
antholoj/dive-mcp:latest <your-image-tag>
```
#### C. MCP Server (Recommended)
When running as an MCP server in a container, ensure you map the port and set the host to `0.0.0.0`.
**1. Streamable HTTP (Modern):**
```bash
docker run --rm -p 8080:8080 \
-v /var/run/docker.sock:/var/run/docker.sock \
antholoj/dive-mcp:latest mcp --transport streamable-http --host 0.0.0.0
```
- **Endpoint:** `http://localhost:8080/mcp`
**2. Stdio (For local agents):**
```bash
docker run --rm -i \
-v /var/run/docker.sock:/var/run/docker.sock \
antholoj/dive-mcp:latest mcp --quiet
```
**3. SSE (Legacy):**
```bash
docker run --rm -p 8080:8080 \
-v /var/run/docker.sock:/var/run/docker.sock \
antholoj/dive-mcp:latest mcp --transport sse --host 0.0.0.0
```
---
## 4. Connecting MCP Clients
### Claude Desktop
Add `dive` to your `claude_desktop_config.json` (usually found in `%APPDATA%\Claude\claude_desktop_config.json` on Windows or `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS).