-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.mqtt.prod
45 lines (33 loc) · 918 Bytes
/
Dockerfile.mqtt.prod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Use Python 3.10 slim as base image
FROM python:3.10-slim AS builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY mqtt/requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
# Final stage
FROM python:3.10-slim
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /app
# Copy wheels from builder
COPY --from=builder /app/wheels /wheels
RUN pip install --no-cache /wheels/*
# Copy project
COPY mqtt .
# Run as non-root user
RUN useradd -m mqtt
RUN chown -R mqtt:mqtt /app
USER mqtt
# Expose port
EXPOSE 8001
# Command to run the application
CMD ["python", "main_app.py"]