fix(docker): resolve 'No module named reflex' in pod
Some checks failed
CD - Build & Deploy / build-and-push (push) Has been cancelled
CD - Build & Deploy / package-helm (push) Has been cancelled
CD - Build & Deploy / deploy-staging (push) Has been cancelled
CD - Build & Deploy / deploy-production (push) Has been cancelled
CD - Build & Deploy / release (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / security (push) Has been cancelled
ci/woodpecker/push/woodpecker Pipeline was successful
Some checks failed
CD - Build & Deploy / build-and-push (push) Has been cancelled
CD - Build & Deploy / package-helm (push) Has been cancelled
CD - Build & Deploy / deploy-staging (push) Has been cancelled
CD - Build & Deploy / deploy-production (push) Has been cancelled
CD - Build & Deploy / release (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / security (push) Has been cancelled
ci/woodpecker/push/woodpecker Pipeline was successful
Problem: Python packages installed in /root/.local but container runs as non-root user 'peikarband' who cannot access /root/ directory. Solution: - Create user before copying dependencies - Copy packages to /home/peikarband/.local instead of /root/.local - Update PATH to point to user's local bin directory - Fix ownership of copied files This ensures the non-root user can access all Python packages including reflex.
This commit is contained in:
18
Dockerfile
18
Dockerfile
@@ -90,20 +90,22 @@ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& apt-get clean
|
||||
|
||||
# Copy Python dependencies from builder
|
||||
COPY --from=builder /root/.local /root/.local
|
||||
# Create non-root user first
|
||||
RUN groupadd -r -g 1000 peikarband && \
|
||||
useradd -r -u 1000 -g peikarband -m -s /bin/bash peikarband && \
|
||||
mkdir -p /app/logs /app/uploads /app/.reflex
|
||||
|
||||
# Copy Python dependencies from builder to user home
|
||||
COPY --from=builder /root/.local /home/peikarband/.local
|
||||
|
||||
# Copy application code from builder
|
||||
COPY --from=builder /build /app
|
||||
|
||||
# Create non-root user with specific UID/GID
|
||||
RUN groupadd -r -g 1000 peikarband && \
|
||||
useradd -r -u 1000 -g peikarband -m -s /bin/bash peikarband && \
|
||||
mkdir -p /app/logs /app/uploads /app/.reflex && \
|
||||
chown -R peikarband:peikarband /app
|
||||
# Fix ownership
|
||||
RUN chown -R peikarband:peikarband /home/peikarband/.local /app
|
||||
|
||||
# Set environment variables
|
||||
ENV PATH=/root/.local/bin:$PATH \
|
||||
ENV PATH=/home/peikarband/.local/bin:$PATH \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONHASHSEED=random \
|
||||
|
||||
Reference in New Issue
Block a user