Skip to content

Commit ed8cc65

Browse files
committed
Add Docker support with Dockerfiles for standard and mcpo-enabled images
1 parent d062380 commit ed8cc65

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

.dockerignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Docker ignore file to reduce build context size
2+
**/__pycache__/
3+
*.pyc
4+
*.pyo
5+
*.pyd
6+
.Python
7+
*.so
8+
.git
9+
.gitignore
10+
.github
11+
.vscode
12+
.idea
13+
*.md
14+
!README.md
15+
.env
16+
.env.*
17+
.env.example
18+
*.log
19+
.coverage
20+
.pytest_cache
21+
.mypy_cache
22+
dist/
23+
build/
24+
*.egg-info/
25+
docker-compose.yml
26+
Dockerfile*
27+
*.tar
28+
*.zip
29+
.venv/

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM python:3.13-alpine3.22 AS builder
2+
3+
RUN pip install --no-cache-dir --upgrade pip \
4+
&& pip install --no-cache-dir uv
5+
6+
WORKDIR /app
7+
8+
RUN --mount=type=cache,target=/root/.cache/uv \
9+
--mount=type=bind,source=uv.lock,target=uv.lock \
10+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
11+
uv sync --locked --no-install-project --no-dev
12+
13+
COPY . /app
14+
15+
RUN --mount=type=cache,target=/root/.cache/uv \
16+
uv sync --locked --no-dev
17+
18+
19+
FROM python:3.13-alpine3.22
20+
ENV PYTHONUNBUFFERED=1
21+
22+
RUN apk add --no-cache ca-certificates \
23+
&& addgroup -g 1000 appuser \
24+
&& adduser -D -u 1000 -G appuser appuser
25+
26+
COPY --from=builder --chown=appuser:appuser /app /app
27+
28+
WORKDIR /app
29+
30+
USER appuser
31+
32+
ENV PATH="/app/.venv/bin:$PATH"
33+
34+
CMD ["python", "-u", "server.py"]

Dockerfile.mcpo

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM python:3.13-alpine3.22 AS builder
2+
3+
RUN pip install --no-cache-dir --upgrade pip \
4+
&& pip install --no-cache-dir uv
5+
6+
WORKDIR /app
7+
8+
RUN --mount=type=cache,target=/root/.cache/uv \
9+
--mount=type=bind,source=uv.lock,target=uv.lock \
10+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
11+
uv sync --locked --no-install-project --no-dev \
12+
&& uv pip install mcpo
13+
14+
COPY . /app
15+
16+
RUN --mount=type=cache,target=/root/.cache/uv \
17+
uv sync --locked --no-dev \
18+
&& uv pip install mcpo
19+
20+
21+
FROM python:3.13-alpine3.22
22+
ENV PYTHONUNBUFFERED=1
23+
24+
RUN apk add --no-cache ca-certificates \
25+
&& addgroup -g 1000 appuser \
26+
&& adduser -D -u 1000 -G appuser appuser
27+
28+
COPY --from=builder --chown=appuser:appuser /app /app
29+
30+
WORKDIR /app
31+
32+
USER appuser
33+
34+
ENV PATH="/app/.venv/bin:$PATH"
35+
36+
HEALTHCHECK \
37+
--interval=30s \
38+
--timeout=10s \
39+
--start-period=30s \
40+
--retries=3 \
41+
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:8000/openapi.json || exit 1
42+
43+
EXPOSE 8000
44+
45+
CMD ["sh", "-c", "if [ -n \"$MCPO_API_KEY\" ]; then exec mcpo --api-key \"$MCPO_API_KEY\" -- python -u server.py; else exec mcpo -- python -u server.py; fi"]

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ This is a simple read-only [Model Context Protocol](https://modelcontextprotocol
5757
> Show me all configuration changes to the core router in the last month
5858
```
5959

60+
## Docker Usage
61+
62+
This repository provides two Dockerfiles:
63+
64+
- `Dockerfile`: Standard image for running the NetBox MCP server. Use this for most deployments, for example in Claude Desktop or VS Code.
65+
- `Dockerfile.mcpo`: Image with [mcpo](https://github.com/open-webui/mcpo) included, mainly for integration with OpenWebUI or other MCP Orchestrators that require the OpenAPI-compatible HTTP MCP server.
66+
67+
To build and run the standard image:
68+
69+
```sh
70+
docker build -t netbox-mcp-server:main .
71+
docker run --rm -e NETBOX_URL=... -e NETBOX_TOKEN=... -p 8000:8000 netbox-mcp-server:main
72+
```
73+
74+
To build and run the mcpo-enabled image (for OpenWebUI):
75+
76+
```sh
77+
docker build -f Dockerfile.mcpo -t netbox-mcp-server:mcpo .
78+
docker run --rm -e NETBOX_URL=... -e NETBOX_TOKEN=... -e MCPO_API_KEY=... -p 8000:8000 netbox-mcp-server:mcpo
79+
```
80+
81+
> Use the `MCPO_API_KEY` environment variable if want to set a API KEY.
82+
83+
6084
## Development
6185

6286
Contributions are welcome! Please open an issue or submit a PR.

0 commit comments

Comments
 (0)