fix: correct Python dependencies path for non-root user in Docker
The builder stage installed dependencies to /root/.local but the final stage switched to the 'aegis' user who couldn't access /root/.local. Fixed by copying dependencies to /home/aegis/.local and updating PATH to point to the correct location.
This commit is contained in:
@@ -22,25 +22,24 @@ FROM python:3.11-slim
|
|||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy Python dependencies from builder
|
# Create non-root user for security
|
||||||
COPY --from=builder /root/.local /root/.local
|
RUN useradd -m -u 1000 -s /bin/bash aegis
|
||||||
|
|
||||||
|
# Copy Python dependencies from builder to aegis user's home
|
||||||
|
COPY --from=builder --chown=aegis:aegis /root/.local /home/aegis/.local
|
||||||
|
|
||||||
# Copy application code
|
# Copy application code
|
||||||
COPY src/ ./src/
|
COPY --chown=aegis:aegis src/ ./src/
|
||||||
|
|
||||||
# Create directory for audit logs
|
# Create directory for audit logs
|
||||||
RUN mkdir -p /var/log/aegis-mcp && \
|
RUN mkdir -p /var/log/aegis-mcp && \
|
||||||
chmod 755 /var/log/aegis-mcp
|
chown -R aegis:aegis /var/log/aegis-mcp
|
||||||
|
|
||||||
# Create non-root user for security
|
|
||||||
RUN useradd -m -u 1000 -s /bin/bash aegis && \
|
|
||||||
chown -R aegis:aegis /app /var/log/aegis-mcp
|
|
||||||
|
|
||||||
# Switch to non-root user
|
# Switch to non-root user
|
||||||
USER aegis
|
USER aegis
|
||||||
|
|
||||||
# Add user's local bin to PATH
|
# Add user's local bin to PATH
|
||||||
ENV PATH=/root/.local/bin:$PATH
|
ENV PATH=/home/aegis/.local/bin:$PATH
|
||||||
ENV PYTHONPATH=/app/src:$PYTHONPATH
|
ENV PYTHONPATH=/app/src:$PYTHONPATH
|
||||||
|
|
||||||
# Expose MCP server port
|
# Expose MCP server port
|
||||||
|
|||||||
Reference in New Issue
Block a user