Files
modbus-slave/Dockerfile
T
zihluwang d781d2fadc
Build and Push Docker Image / build (push) Canceled after 0s
fix(docker): multi-stage build and publish tags
- Split Dockerfile into builder and runtime stages
- Put .venv on PATH so pymodbus resolves in the container
- Push image to Docker Hub and GHCR with latest and 7-char SHA tags
- Use real repo/image names in README
2026-08-31 11:59:37 +08:00

27 lines
536 B
Docker

# Stage 1: build and install dependencies
FROM python:3.11-slim AS builder
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN pip install --no-cache-dir uv && uv sync --frozen --no-dev --no-install-project
# Stage 2: runtime (slim, no build toolchain)
FROM python:3.11-slim AS runtime
WORKDIR /app
COPY --from=builder /app/.venv ./.venv
ENV PATH="/app/.venv/bin:$PATH"
# Copy application
COPY main.py ./
# Create non-root user
RUN useradd -m modbus && chown -R modbus:modbus /app
USER modbus
EXPOSE 5020
CMD ["python", "main.py"]