Skip to content

Commit ed92c96

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

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM python:3.13-alpine3.22 AS builder
2+
3+
RUN apk add --no-cache \
4+
gcc \
5+
musl-dev \
6+
libffi-dev \
7+
&& pip install --no-cache-dir --upgrade pip \
8+
&& pip install --no-cache-dir uv
9+
10+
COPY pyproject.toml uv.lock LICENSE README.md ./
11+
RUN uv pip install --system --target /tmp/packages --requirements pyproject.toml
12+
13+
FROM python:3.13-alpine3.22
14+
15+
RUN apk add --no-cache \
16+
ca-certificates \
17+
&& addgroup -g 1000 appuser \
18+
&& adduser -D -u 1000 -G appuser appuser
19+
20+
COPY --from=builder /tmp/packages /usr/local/lib/python3.13/site-packages/
21+
22+
WORKDIR /app
23+
COPY . .
24+
25+
RUN chown -R appuser:appuser /app
26+
27+
USER appuser
28+
29+
ENV PYTHONPATH=/usr/local/lib/python3.13/site-packages:/app
30+
31+
CMD ["python", "-u", "server.py"]

Dockerfile.mcpo

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM python:3.13-alpine3.22 AS builder
2+
3+
RUN apk add --no-cache \
4+
gcc \
5+
musl-dev \
6+
libffi-dev \
7+
&& pip install --no-cache-dir --upgrade pip \
8+
&& pip install --no-cache-dir uv
9+
10+
COPY pyproject.toml uv.lock LICENSE README.md ./
11+
RUN uv pip install --system --target /tmp/packages --requirements pyproject.toml \
12+
&& uv pip install --system --target /tmp/packages mcpo
13+
14+
FROM python:3.13-alpine3.22
15+
16+
RUN apk add --no-cache \
17+
ca-certificates \
18+
&& addgroup -g 1000 appuser \
19+
&& adduser -D -u 1000 -G appuser appuser
20+
21+
COPY --from=builder /tmp/packages /usr/local/lib/python3.13/site-packages/
22+
COPY --from=builder /tmp/packages/bin/mcpo /usr/local/bin/mcpo
23+
24+
WORKDIR /app
25+
COPY . .
26+
27+
RUN chown -R appuser:appuser /app
28+
29+
USER appuser
30+
31+
ENV PYTHONPATH=/usr/local/lib/python3.13/site-packages:/app
32+
33+
HEALTHCHECK \
34+
--interval=30s \
35+
--timeout=10s \
36+
--start-period=30s \
37+
--retries=3 \
38+
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:8000/openapi.json || exit 1
39+
40+
EXPOSE 8000
41+
42+
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)