Skip to content

Commit 0ab865e

Browse files
CopilotmaniSbindra
andcommitted
Use Azure Linux recommended base images in Dockerfile multistage build
Co-authored-by: maniSbindra <6338721+maniSbindra@users.noreply.github.com>
1 parent 57e93c3 commit 0ab865e

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

Dockerfile

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
# Multi-stage Dockerfile for Container Image Recommendation MCP Server
2-
FROM python:3.12-slim AS base
2+
# Build stage using recommended Azure Linux base image
3+
FROM mcr.microsoft.com/azurelinux/base/python:3.12 AS builder
34

45
# Set working directory
56
WORKDIR /app
67

7-
# Install system dependencies
8-
RUN apt-get update && apt-get install -y \
9-
curl \
10-
sqlite3 \
11-
ca-certificates \
12-
&& rm -rf /var/lib/apt/lists/*
13-
14-
# Install external tools required for image analysis (optional for MCP server)
15-
RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin || echo "Syft installation failed, continuing..." && \
16-
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin || echo "Grype installation failed, continuing..." && \
17-
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin || echo "Trivy installation failed, continuing..."
18-
198
# Copy requirements and install Python dependencies
209
COPY requirements.txt .
2110
RUN pip install --no-cache-dir --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r requirements.txt
2211

12+
# Runtime stage using recommended Azure Linux base image
13+
FROM mcr.microsoft.com/azurelinux/base/python:3.12 AS runtime
14+
15+
# Set working directory
16+
WORKDIR /app
17+
18+
# Copy Python dependencies from builder stage
19+
COPY --from=builder /usr/lib/python3.12/site-packages /usr/lib/python3.12/site-packages
20+
2321
# Copy source code
2422
COPY src/ ./src/
2523
COPY mcp_server.py .
2624
COPY azure_linux_images.db .
2725

28-
# Create non-root user for security
29-
RUN useradd -m -u 1000 mcpuser && \
30-
chown -R mcpuser:mcpuser /app
26+
# Use existing non-root user for security
27+
RUN chown -R nonroot:nonroot /app
3128

32-
USER mcpuser
29+
USER nonroot
3330

34-
# Verify core functionality (tools are optional)
35-
RUN python -c "import sys; sys.path.append('/app/src'); from database import ImageDatabase; print('✓ Database access working')"
31+
# Verify core functionality
32+
RUN python3 -c "import sys; sys.path.append('/app/src'); from database import ImageDatabase; print('✓ Database access working')"
3633

3734
# Expose port for potential HTTP interface (optional)
3835
EXPOSE 8080
@@ -42,11 +39,11 @@ ENV PYTHONPATH=/app/src
4239
ENV MCP_DB_PATH=/app/azure_linux_images.db
4340

4441
# Default command runs the MCP server
45-
CMD ["python", "mcp_server.py"]
42+
CMD ["python3", "mcp_server.py"]
4643

4744
# Health check
4845
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
49-
CMD python -c "import sys; sys.path.append('/app/src'); from database import ImageDatabase; db = ImageDatabase('/app/azure_linux_images.db'); stats = db.get_vulnerability_statistics(); db.close(); print('Health check passed')" || exit 1
46+
CMD python3 -c "import sys; sys.path.append('/app/src'); from database import ImageDatabase; db = ImageDatabase('/app/azure_linux_images.db'); stats = db.get_vulnerability_statistics(); db.close(); print('Health check passed')" || exit 1
5047

5148
# Labels for metadata
5249
LABEL org.opencontainers.image.title="Container Image Recommendation MCP Server"

0 commit comments

Comments
 (0)