Guide · AWS Elastic Beanstalk · Docker Platform
MCP Server on Elastic Beanstalk Docker Platform — Single-Container and ECR Image Deployment
Elastic Beanstalk's Docker platform lets you deploy any containerized MCP server — Python, TypeScript, Rust, or any custom runtime — without managing EC2 instances directly: ship a Dockerfile or reference an ECR image in Dockerrun.aws.json, and EB handles the Docker daemon, image pull, container lifecycle, and nginx reverse proxy configuration. This guide covers the single-container Docker deployment workflow, the Dockerrun.aws.json v3 format for ECR-hosted images, IAM permissions for ECR and Secrets Manager, the multi-container sidecar pattern for MCP session state, and eb local run for local testing. For the Node.js managed platform, see Elastic Beanstalk Node.js Platform. For scaling the Docker platform environment, see Elastic Beanstalk Auto-Scaling. For .ebextensions on Docker, see Environment Configuration.
TL;DR
Place a Dockerfile in your project root for EB to build and run on-instance. For ECR-hosted images, use Dockerrun.aws.json with the ECR image URI — the EB instance profile needs ecr:GetAuthorizationToken, ecr:BatchGetImage, and ecr:GetDownloadUrlForLayer. Containers on the Docker platform must expose port 80 (or the port that nginx proxies to); there is no automatic port 8080 injection as with the Node.js platform. Build, tag, and push to ECR before each eb deploy that changes the image.
Docker platform vs. Node.js managed platform: when to choose Docker
The Node.js managed platform (covered in the Node.js guide) is the fastest path for a standard Node.js MCP server: no container build step, no image registry, and EB handles npm install automatically. The Docker platform is the right choice when:
- Non-Node.js runtime: Python MCP servers (using the
mcpPyPI package), Rust-based MCP servers, or Java MCP implementations all require Docker since EB's managed platforms only cover specific language runtimes. - Pinned system dependencies: An MCP server that calls FFmpeg, Pandoc, or other native binaries needs them installed in the container image at a known version — not managed by EB's platform AMI.
- Exact Node.js version: EB's managed Node.js platform lags behind upstream releases by several weeks. If your MCP server requires a specific Node.js patch version, pin it in a Dockerfile with
FROM node:20.18.1-alpine. - Multi-stage builds: TypeScript compilation in a build stage, production runtime in a slim stage, without shipping TypeScript compiler packages or source maps to the EB instance.
- Sidecar process: An MCP server that co-locates a Valkey/Redis process for in-memory session state, without the overhead of an external ElastiCache cluster.
The Docker platform on EB runs the Docker daemon directly on the EC2 instance. It is not ECS Fargate — your containers run on EC2, with full access to instance-level resources and the EB configuration model.
Single-container Dockerfile deployment
The simplest Docker platform deployment: place a Dockerfile in your project root. EB builds the image on the EC2 instance during deployment and runs the resulting container. No ECR push required for this workflow.
# Dockerfile for a TypeScript MCP server (multi-stage build)
FROM node:20.18-alpine AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY tsconfig.json ./
COPY src/ ./src/
RUN npm run build # outputs to dist/
# Production stage — only runtime dependencies
FROM node:20.18-alpine AS runtime
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY --from=builder /app/dist ./dist
# EB Docker platform: expose port 80 (nginx proxies to this port)
# Unlike the Node.js platform, there is no PORT=8080 injection
EXPOSE 80
ENV NODE_ENV=production
ENV PORT=80
CMD ["node", "dist/server.js"]
Critical distinction from the Node.js platform: on the Docker platform, EB's nginx proxy forwards to port 80 of the container by default. If your MCP server listens on a different port, you must configure the proxy. Set EXPOSE 8080 in the Dockerfile and add an .ebextensions option to tell nginx the upstream port:
# .ebextensions/docker-proxy.config — configure nginx upstream port
option_settings:
aws:elasticbeanstalk:environment:proxy:
ProxyServer: nginx
files:
"/etc/nginx/conf.d/proxy.conf":
mode: "000644"
owner: root
group: root
content: |
upstream nodejs {
server 127.0.0.1:8080;
keepalive 256;
}
server {
listen 80;
location / {
proxy_pass http://nodejs;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Required for SSE transport: disable proxy buffering
proxy_buffering off;
proxy_cache off;
}
}
The proxy_buffering off directive is critical for SSE-based MCP servers: nginx's default response buffering accumulates SSE events and delivers them in bursts rather than streaming them to the client, breaking the SSE protocol semantics.
Dockerrun.aws.json v3: ECR image deployment
When you pre-build images and push them to ECR, use Dockerrun.aws.json in place of (or alongside) a Dockerfile. The v3 format uses ECS task definition container definition syntax, which gives you full control over resource limits, environment variable injection, secrets resolution, and log configuration.
{
"AWSEBDockerrunVersion": "3",
"containerDefinitions": [
{
"name": "mcp-server",
"image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/mcp-server:1.4.2",
"essential": true,
"memory": 512,
"memoryReservation": 256,
"portMappings": [
{
"hostPort": 80,
"containerPort": 80,
"protocol": "tcp"
}
],
"environment": [
{ "name": "NODE_ENV", "value": "production" },
{ "name": "MCP_LOG_LEVEL", "value": "info" },
{ "name": "PORT", "value": "80" }
],
"secrets": [
{
"name": "DB_URL",
"valueFrom": "arn:aws:secretsmanager:us-east-1:123456789012:secret:mcp-server/db-url-AbCdEf"
},
{
"name": "OPENAI_API_KEY",
"valueFrom": "arn:aws:secretsmanager:us-east-1:123456789012:secret:mcp-server/openai-key-XyZ123"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/aws/elasticbeanstalk/mcp-server-prod",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "mcp-server"
}
},
"healthCheck": {
"command": ["CMD-SHELL", "curl -sf http://localhost/health || exit 1"],
"interval": 30,
"timeout": 5,
"retries": 3,
"startPeriod": 60
}
}
]
}
The secrets array resolves values from Secrets Manager at container start time. The ECS-style secret resolution is handled by the ECS agent running on the EB instance — the secret ARN must refer to either an entire secret (returns the full JSON string) or a specific JSON key within the secret (use the format arn:...:secret:name:SecretString:key::).
IAM permissions for ECR image pull
EB's instance profile must have ECR read permissions for the Docker daemon to pull from your private ECR repository. The minimum permission set for ECR pull:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ECRGetAuthToken",
"Effect": "Allow",
"Action": "ecr:GetAuthorizationToken",
"Resource": "*"
},
{
"Sid": "ECRImagePull",
"Effect": "Allow",
"Action": [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchCheckLayerAvailability"
],
"Resource": "arn:aws:ecr:us-east-1:123456789012:repository/mcp-server"
}
]
}
Note that ecr:GetAuthorizationToken must have Resource: "*" — it cannot be scoped to a specific repository because the authorization token is account-wide. Add this policy to the aws-elasticbeanstalk-ec2-role.
For secrets resolution in Dockerrun.aws.json, the instance profile also needs Secrets Manager access:
{
"Sid": "SecretsManagerForContainerSecrets",
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret"
],
"Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:mcp-server/*"
}
Add both policies as a single inline policy on the EB EC2 role:
aws iam put-role-policy \
--role-name aws-elasticbeanstalk-ec2-role \
--policy-name mcp-docker-runtime \
--policy-document file://mcp-docker-policy.json
Build pipeline: push to ECR before eb deploy
Unlike the Node.js platform where EB runs npm install on-instance, the Docker platform with ECR images requires you to push a new image before deploying. The standard pipeline:
#!/bin/bash
# deploy.sh — build, push to ECR, update Dockerrun.aws.json, deploy to EB
set -euo pipefail
REGION="us-east-1"
ACCOUNT_ID="123456789012"
ECR_REPO="mcp-server"
IMAGE_TAG=$(git rev-parse --short HEAD) # use git SHA as immutable tag
ECR_URI="${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/${ECR_REPO}"
echo "Building image ${ECR_URI}:${IMAGE_TAG}"
docker build --platform linux/amd64 -t "${ECR_URI}:${IMAGE_TAG}" .
echo "Authenticating to ECR"
aws ecr get-login-password --region "${REGION}" \
| docker login --username AWS --password-stdin "${ECR_URI}"
echo "Pushing image to ECR"
docker push "${ECR_URI}:${IMAGE_TAG}"
echo "Updating Dockerrun.aws.json with new image tag"
# Use jq to update only the image field, preserving all other config
jq --arg img "${ECR_URI}:${IMAGE_TAG}" \
'.containerDefinitions[0].image = $img' \
Dockerrun.aws.json > Dockerrun.aws.json.tmp \
&& mv Dockerrun.aws.json.tmp Dockerrun.aws.json
echo "Deploying to Elastic Beanstalk"
eb deploy mcp-server-prod --message "deploy ${IMAGE_TAG}"
echo "Deployment complete"
Using the git short SHA as the image tag creates an immutable tag per commit — you can always trace which code version is running from the ECR image tag. Avoid using :latest as the tag for production deployments; it makes rollback ambiguous and can mask which version is actually deployed.
For CI/CD pipelines (GitHub Actions, CodePipeline), configure OIDC-based role assumption rather than long-lived IAM access keys. The pipeline role needs ecr:* on the repository, elasticbeanstalk:CreateApplicationVersion, elasticbeanstalk:UpdateEnvironment, and s3:PutObject on the EB artifacts bucket.
Multi-container sidecar: MCP server + Valkey for session state
SSE-based MCP servers accumulate session state in memory: the tool call history, the client's capability negotiation, and any in-progress streaming responses. When EB scales out to multiple instances, sticky sessions (covered in the autoscaling guide) ensure a client always reaches the same instance — but during instance replacement, in-memory session state is lost.
A Valkey (open-source Redis fork) sidecar container on the same EC2 instance provides low-latency session state persistence without the operational overhead of an ElastiCache cluster for small deployments. Since both containers share the host network namespace in EB's Docker platform, they communicate via localhost:
{
"AWSEBDockerrunVersion": "3",
"containerDefinitions": [
{
"name": "mcp-server",
"image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/mcp-server:1.4.2",
"essential": true,
"memory": 512,
"memoryReservation": 256,
"portMappings": [
{ "hostPort": 80, "containerPort": 80, "protocol": "tcp" }
],
"environment": [
{ "name": "NODE_ENV", "value": "production" },
{ "name": "PORT", "value": "80" },
{ "name": "REDIS_URL", "value": "redis://localhost:6379" }
],
"secrets": [
{
"name": "MCP_SESSION_SECRET",
"valueFrom": "arn:aws:secretsmanager:us-east-1:123456789012:secret:mcp-server/session-secret-AbCd"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/aws/elasticbeanstalk/mcp-server-prod",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "mcp-server"
}
},
"dependsOn": [
{ "containerName": "valkey", "condition": "START" }
]
},
{
"name": "valkey",
"image": "public.ecr.aws/docker/library/valkey:7.2-alpine",
"essential": false,
"memory": 128,
"memoryReservation": 64,
"portMappings": [
{ "hostPort": 6379, "containerPort": 6379, "protocol": "tcp" }
],
"command": [
"valkey-server",
"--maxmemory", "100mb",
"--maxmemory-policy", "allkeys-lru",
"--save", ""
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/aws/elasticbeanstalk/mcp-server-prod",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "valkey"
}
}
}
]
}
The dependsOn condition START means the MCP server container starts only after the Valkey container has started (not after it passes a health check — use HEALTHY for that, which requires a healthCheck block on the Valkey container). The essential: false on the Valkey container means the task group continues if Valkey crashes; set it to true if your MCP server cannot function without session state persistence.
Note: this pattern stores session state per-instance. Cross-instance session state sharing requires an external Redis/Valkey cluster (ElastiCache) accessible to all EB instances — connect via the VPC-internal endpoint at redis://{cluster-endpoint}:6379.
eb local run: local testing before deployment
The EB CLI provides eb local run to run your Docker configuration locally using the same Docker command that EB uses on the instance. This is useful for catching PORT or volume mount misconfigurations before pushing to EB:
# Run the EB Docker configuration locally
eb local run --port 8080
# This is equivalent to:
# docker run -p 8080:80 --env-file {image}
# Test the health check endpoint
curl http://localhost:8080/health
# Run with environment variable overrides for local dev
eb local run --envvars NODE_ENV=development,MCP_LOG_LEVEL=debug
eb local run does not emulate ECS-style secret resolution from Secrets Manager. The secrets entries in Dockerrun.aws.json are ignored during eb local run — the container starts without those environment variables. For local testing with secrets, use a .env file and Docker Compose outside of the EB toolchain.
Also note that eb local run does not emulate the EB nginx proxy layer — the container's port is exposed directly on the specified --port. Test your MCP server's SSE transport directly on that port:
# Test SSE connection locally
curl -N -H "Accept: text/event-stream" http://localhost:8080/sse
# Expected: event stream headers and initial connection event
# data: {"jsonrpc":"2.0","method":"connection/established","params":{}}
.ebextensions on the Docker platform
The .ebextensions/ directory works identically on the Docker platform as on the Node.js platform for option_settings blocks. However, the lifecycle of files and commands is different: they run on the host EC2 instance, not inside the container. This matters for:
# .ebextensions/docker-options.config
option_settings:
# Set health check URL — Docker platform checks the container's HTTP port
aws:elasticbeanstalk:application:
Application Healthcheck URL: /health
# ALB for SSE-based MCP server
aws:elasticbeanstalk:environment:
LoadBalancerType: application
# Enhanced health reporting
aws:elasticbeanstalk:healthreporting:system:
SystemType: enhanced
HealthStreamingEnabled: true
# CloudWatch Logs for the EB agent (not the container — container logs
# go to CloudWatch via the awslogs log driver in Dockerrun.aws.json)
aws:elasticbeanstalk:cloudwatch:logs:
StreamLogs: true
RetentionInDays: 30
# container_commands run after app bundle extraction on the host
# This is NOT inside the container — it's the EC2 host
container_commands:
01-verify-ecr-credentials:
command: |
aws ecr get-login-password --region us-east-1 \
| docker login --username AWS --password-stdin \
123456789012.dkr.ecr.us-east-1.amazonaws.com
leader_only: false
The container_commands block in .ebextensions on the Docker platform runs on the host EC2 before Docker starts. This is useful for pre-pulling images to warm up the Docker layer cache, verifying ECR credentials, or running pre-deployment checks. For post-deployment actions (database migrations inside the container), use .platform/hooks/postdeploy/ scripts as described in Environment Configuration.
Complete example: TypeScript MCP server with ECR and Secrets Manager
This is a complete deployment configuration for a production TypeScript MCP server using ECR for image storage and Secrets Manager for API key injection.
project/
├── Dockerfile # multi-stage TypeScript build
├── Dockerrun.aws.json # ECR image + secrets config
├── .ebignore # exclude node_modules, src/, .env
└── .ebextensions/
├── options.config # health check, ALB, enhanced health
└── iam.config # ECR + secrets IAM inline policy ref
# Dockerfile (multi-stage TypeScript → production Node.js)
FROM node:20.18-alpine AS builder
WORKDIR /app
COPY package.json package-lock.json tsconfig.json ./
RUN npm ci
COPY src/ ./src/
RUN npm run build
FROM node:20.18-alpine AS runtime
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY --from=builder /app/dist ./dist
EXPOSE 80
ENV NODE_ENV=production PORT=80
CMD ["node", "dist/server.js"]
// Dockerrun.aws.json
{
"AWSEBDockerrunVersion": "3",
"containerDefinitions": [
{
"name": "mcp-server",
"image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/mcp-server:REPLACE_WITH_SHA",
"essential": true,
"memory": 512,
"portMappings": [{ "hostPort": 80, "containerPort": 80 }],
"environment": [
{ "name": "NODE_ENV", "value": "production" },
{ "name": "PORT", "value": "80" }
],
"secrets": [
{
"name": "ANTHROPIC_API_KEY",
"valueFrom": "arn:aws:secretsmanager:us-east-1:123456789012:secret:mcp-server/anthropic-key-AbCd"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/aws/elasticbeanstalk/mcp-server-prod",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "mcp-server"
}
},
"healthCheck": {
"command": ["CMD-SHELL", "wget -qO- http://localhost/health | grep -q ok || exit 1"],
"interval": 30,
"timeout": 10,
"retries": 3,
"startPeriod": 60
}
}
]
}
After deploying, monitor the /health endpoint at https://mcp-server-prod.{region}.elasticbeanstalk.com/health with AliveMCP for external uptime visibility. EB's internal enhanced health reporting only surfaces instance-level metrics inside the EB console — an external check catches network-level and DNS-level failures that EB cannot observe.