How to Deploy an MCP Server with Docker

How to Deploy an MCP Server with Docker

Building an MCP server is only the first step in making it useful to AI applications. To make your server accessible to external clients, you need to package the application, configure its network access, and deploy it in an environment where it can run reliably.

Docker simplifies this process by packaging the MCP server and its dependencies into a portable container. This tutorial walks through deploying a NitroStack MCP server with Docker, configuring Streamable HTTP, verifying the deployment, and using Docker Compose when supporting services are required.

TL;DR

To deploy a NitroStack MCP server with Docker, configure it to use HTTP transport and bind to 0.0.0.0, create a Dockerfile, build the image, and run the container with port 3000 mapped to the host. The MCP endpoint is /mcp. Check /mcp/health and test tool discovery and execution with an MCP-compatible client before exposing it to remote users.

Quick commands:

bash
docker build -t my-mcp-server .
docker run -d --name mcp-server -p 3000:3000 my-mcp-server
curl http://localhost:3000/mcp/health

Understanding the MCP Server Deployment Architecture

An MCP server running locally is typically available only within its development environment. A deployed MCP server needs to be reachable by the clients that consume its tools and resources.

Docker acts as the packaging and runtime layer between your application and the deployment infrastructure. Instead of manually installing dependencies and configuring the runtime on every server, you build a container image and run that image in your target environment.

Deployment flow:

MCP application → Docker image → Running container → Network endpoint → MCP client

LayerWhat it does
MCP applicationContains the tools, resources, and logic exposed to AI clients.
Docker imagePackages the application, compiled files, and required dependencies.
ContainerRuns the packaged application in an isolated environment.
Network endpointMakes the MCP server reachable through its configured host and port.
MCP clientConnects to the deployed server and discovers or executes its capabilities.

For NitroStack, this deployment uses HTTP transport, binds to 0.0.0.0, and exposes port 3000. The MCP endpoint is /mcp.

Why Docker Is Useful for MCP Server Deployment

An MCP server may depend on a specific Node.js version, packages, compiled TypeScript files, environment variables, and additional build artifacts. Installing and configuring these manually on every deployment environment can lead to inconsistent behavior.

Docker creates a repeatable runtime environment and helps separate the build process from the production runtime. With a multi-stage build, you can:

  • Install dependencies and build the application in a dedicated stage.
  • Compile TypeScript into production-ready JavaScript.
  • Build UI widgets when the project uses them.
  • Exclude development dependencies from the final runtime image.
  • Move the same image between supported deployment environments.

The result is a more predictable deployment, although Docker alone does not configure authentication, monitoring, backups, or scaling.

Prerequisites

Before containerizing the application, confirm that the project builds successfully in your development environment. Resolve compilation errors and verify that required files and dependencies are present.

You will need:

  • Docker installed on your deployment machine.
  • A working NitroStack MCP server project.
  • A valid package.json and build script.
  • A Dockerfile in the project root.
  • Required environment variables configured.
  • Network access configured for the intended MCP clients.

Environment configuration

The main environment variables used in this example are:

VariableExample valuePurpose
NODE_ENVproductionRuns the app in production mode.
HOST0.0.0.0Listens on the container network interfaces.
PORT3000Sets the application listening port.
MCP_TRANSPORT_TYPEhttpConfigures HTTP transport.

Binding to 0.0.0.0 is important inside a container. If the server listens only on localhost, traffic forwarded from Docker's network may not reach it. Docker's port mapping controls how the host exposes the service.

Keep API keys, database passwords, and other credentials out of the Dockerfile and source repository. Supply secrets at runtime or through your hosting platform's secret manager.

How to Deploy an MCP Server with Docker

Deploying an MCP server with Docker involves preparing the application, configuring its HTTP transport, building a container image, and running it with the appropriate port mapping. With NitroStack, this example uses Streamable HTTP on port 3000 and exposes the /mcp endpoint. After starting the container, check its health and test it with an MCP-compatible client.

Deployment at a glance

  1. Configure HTTP transport and bind to 0.0.0.0.
  2. Create a Dockerfile that installs dependencies and builds the application.
  3. Build the image with docker build.
  4. Run the container and publish its port.
  5. Verify health, logs, and MCP client functionality.

Step 1: Create a Dockerfile

Create a file named Dockerfile in the project root. It describes the steps Docker uses to build and start your application.

dockerfile
FROM node:20-alpine AS builder
WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app

ENV NODE_ENV=production \
    HOST=0.0.0.0 \
    PORT=3000 \
    MCP_TRANSPORT_TYPE=http

COPY package*.json ./
RUN npm ci --omit=dev

COPY --from=builder /app/dist ./dist
COPY --from=builder /app/src/widgets/out ./src/widgets/out

USER node
EXPOSE 3000

HEALTHCHECK --interval=30s --timeout=3s --start-period=10s \
  CMD wget -qO- http://localhost:3000/mcp/health || exit 1

CMD ["node", "dist/index.js"]

This Dockerfile uses a multi-stage build. The builder stage installs dependencies, copies the source, and runs the build. The runtime stage starts from a clean Node.js image, installs only production dependencies, and copies compiled artifacts from the builder.

Why use two stages? Build tools and development dependencies are often unnecessary when the app is running. Separating them can reduce the runtime image's contents and simplify what ships to production. The example also runs as the non-root node user.

Project-specific note: If your project does not generate src/widgets/out, remove that COPY line. Confirm the build output paths, health endpoint, and start command match your NitroStack project before using this Dockerfile.

Step 2: Configure the runtime environment

The example sets its runtime variables in the Dockerfile. If you prefer to keep deployment configuration separate, use an environment file or your platform's environment settings.

env
NODE_ENV=production
HOST=0.0.0.0
PORT=3000
MCP_TRANSPORT_TYPE=http

Separating configuration from code makes it easier to use the same image across development, staging, and production. Environment-specific values can change without rebuilding the application, provided those settings are read at runtime.

Step 3: Build the Docker image

From the project root, run:

bash
docker build -t my-mcp-server .

Docker reads the Dockerfile, installs dependencies, compiles the project, and assembles the runtime image. The -t flag gives the image the name my-mcp-server, which you can reference when starting a container.

Step 4: Run the container

Start your container in detached mode and publish port 3000:

bash
docker run -d \
  --name mcp-server \
  -p 3000:3000 \
  my-mcp-server

The options in this command mean:

  • -d — run the container in the background.
  • --name mcp-server — assign a convenient container name.
  • -p 3000:3000 — map host port 3000 to container port 3000.

Once it is running, the local MCP endpoint is:

http://localhost:3000/mcp

For a remote deployment, replace localhost with the server's IP address or domain. Make sure the firewall, cloud network rules, and any reverse proxy allow the intended traffic. For production, prefer a properly configured HTTPS endpoint rather than exposing an unprotected service directly.

Step 5: Verify the deployment

A container can start successfully while the application inside it is still misconfigured. Check the health endpoint, inspect logs when needed, and test a real MCP client connection.

Health check:

bash
curl http://localhost:3000/mcp/health

A response may look like this:

json
{
  "status": "ok",
  "transport": "streamable-http",
  "sessions": 0,
  "uptime": 4.2
}

This sample response indicates the server reports a healthy state, the configured transport, the session count, and its uptime. Your actual response may differ.

Inspect the logs:

bash
docker logs mcp-server

Confirm the client workflow:

  • Connect using an MCP-compatible client and the configured /mcp endpoint.
  • Confirm the client can discover the server's tools or resources.
  • Execute a test tool and verify the expected response.

A health endpoint checks server availability; a client test verifies that the MCP workflow is functioning end-to-end.

Running the MCP Server with Docker Compose

Docker is usually enough when your MCP server runs as a single container. If the application also needs a database, cache, or another service, Docker Compose lets you define and manage them together in a YAML file.

For example, this Compose file defines an MCP service and a PostgreSQL database:

yaml
services:
  mcp-server:
    build: .
    ports:
      - "3000:3000"
    env_file: .env.production
    depends_on:
      - database
    restart: unless-stopped

  database:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: myapp
      POSTGRES_USER: app
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - db-data:/var/lib/postgresql/data

volumes:
  db-data:

Compose creates a network for the services. From the MCP server container, the database can typically be reached using the service hostname database, rather than localhost. The named volume db-data persists PostgreSQL data when the container is recreated.

Start the services:

bash
docker compose up -d

View their status:

bash
docker compose ps

Check the MCP server logs:

bash
docker compose logs -f mcp-server

Important: depends_on controls startup order but, by itself, does not guarantee that the database is ready to accept connections. Configure application retries or a database health check if your app requires readiness handling. Use secrets management instead of committing real credentials to .env.production.

Docker vs. Docker Compose

Both tools run containers, but they address different deployment needs.

FeatureDocker CLIDocker Compose
Main purposeBuild and run individual containersDefine and manage multi-service applications
ConfigurationCommand-line flagsYAML configuration file
Service managementManage containers individuallyStart, stop, and coordinate services together
Best fitStandalone MCP serverMCP server plus database, cache, or other services
Typical commanddocker rundocker compose up -d

Which should you choose? Start with Docker for a standalone MCP server. Use Compose when the deployment has multiple components or you want repeatable service configuration in one file.

Troubleshooting Common Deployment Issues

When a deployment fails, check the container state and logs first. Then verify configuration, files, and network access. This order helps narrow the cause without changing several settings at once.

SymptomLikely causeWhat to check
Connection refusedWrong host binding or port mappingConfirm HOST=0.0.0.0 and published port values.
Container exits shortly after startingApplication startup error or missing dependencyRun docker logs mcp-server; check the command and runtime files.
Health check is unhealthyEndpoint not responding or incorrect health-check pathConfirm the server is listening and that /mcp/health is valid for your build.
Widgets do not loadWidget artifacts were not generated or copiedVerify the build output directory and Docker COPY paths.
Remote client cannot connectFirewall, DNS, proxy, TLS, or transport mismatchCheck network rules and the public endpoint from outside the host.
Database connection errorsIncorrect connection values or database not readyCheck hostname, credentials, connection string, and readiness/retry behavior.

Useful Docker commands for debugging

bash
# List running containers
docker ps

# Show logs from the MCP container
docker logs mcp-server

# Follow logs live
docker logs -f mcp-server

# Inspect the container configuration and state
docker inspect mcp-server

# Stop and remove the container
docker stop mcp-server
docker rm mcp-server

These commands help determine whether the problem is the application process, container configuration, or networking layer.

Production Deployment Considerations

A successful Docker deployment is only the starting point for production. Once the endpoint is reachable, secure the server and prepare it for operational issues.

  • Restrict network access to intended clients and endpoints.
  • Implement authentication and authorization for exposed tools and resources.
  • Keep credentials out of source code, Docker images, and public logs.
  • Monitor health, errors, and resource usage.
  • Maintain application and container logs with appropriate retention.
  • Use persistent storage for data that must survive container recreation.
  • Rebuild and redeploy images when code or dependencies change.
  • Plan for concurrent connections, resource limits, and scaling.

Docker standardizes the runtime environment, but security, availability, monitoring, backups, and scaling still depend on your application and infrastructure configuration.

From Local Development to Production

Deploying an MCP server with Docker creates a repeatable path from local development to a remote environment. Package the application, configure HTTP transport, expose the endpoint, and verify its health. Then add the infrastructure and operational controls required for your use case.

For NitroStack, the deployment pattern in this guide uses HTTP transport, port 3000, the /mcp endpoint, and a health endpoint for basic verification. Begin with a working application, containerize it, test the complete client workflow, and only then expose it to external clients.

Frequently Asked Questions

Can I deploy an MCP server using Docker?

Yes. Docker packages an MCP application and its dependencies into a portable container image that can run on compatible infrastructure. It helps maintain a consistent runtime across development, staging, and production, reducing differences caused by manually installing dependencies or configuring servers. You still need to configure networking, secrets, authentication, and monitoring for your environment.

What port does NitroStack use for Docker deployment?

This deployment example uses port 3000 for the NitroStack MCP server. The application port is set with the PORT environment variable, while Docker's port mapping determines which host port is exposed. The host and container ports can differ; for example, a host port can forward traffic to container port 3000.

How do I check whether my MCP server is running?

Request the server's /mcp/health endpoint to check its reported status, and inspect the container logs with docker logs mcp-server if something looks wrong. After the health response succeeds, connect an MCP-compatible client and test tool discovery and execution. That final client test checks more than container startup—it verifies the server's MCP interaction path.

Should I use Docker or Docker Compose for an MCP server?

Use Docker for a standalone MCP server that can run by itself. Docker Compose is a better fit when your deployment includes supporting services, such as PostgreSQL or a cache, because you can define their configuration, networking, and lifecycle together in one YAML file. Compose simplifies coordination, but you still need to handle service readiness and credentials.

What are common mistakes when deploying an MCP server?

Common deployment mistakes include binding only to localhost, publishing the wrong port, leaving compiled files out of the runtime image, placing secrets in the Dockerfile, and assuming a running container is fully functional. Check host and port settings, build artifacts, logs, health checks, firewall rules, and then test the endpoint from an MCP client.

Is deploying an MCP server with Docker free?

Docker's core containerization tools can be used without a software license fee, but running a deployment may still cost money. Expenses can include a server or cloud instance, storage, network traffic, monitoring, and paid services used by the MCP application. Total cost depends on the hosting provider, resource needs, usage, and any supporting infrastructure.

Can I host an MCP server without Docker?

Yes. You can host an MCP server on a virtual machine or another supported environment by installing its runtime and dependencies, configuring the application, and managing the service and network yourself. Docker is not mandatory; it mainly makes packaging and environment consistency easier. Choose the approach that fits your deployment workflow, operational experience, and infrastructure requirements.

Subscribe to our newsletter