Update Dockerfile
Browse files- Dockerfile +19 -9
Dockerfile
CHANGED
@@ -2,8 +2,9 @@ FROM python:3.10-slim
|
|
2 |
|
3 |
# Set environment variables
|
4 |
ENV PYTHONUNBUFFERED=1
|
5 |
-
# Still good practice for preventing interactive prompts during apt-get install
|
6 |
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
7 |
|
8 |
# Install system dependencies (ffmpeg, fontconfig for managing copied fonts)
|
9 |
RUN apt-get update && \
|
@@ -16,28 +17,37 @@ RUN apt-get update && \
|
|
16 |
rm -rf /var/lib/apt/lists/*
|
17 |
|
18 |
# Create directory for custom fonts and copy your font file(s)
|
19 |
-
# Make sure 'assets/fonts/arial.ttf' (or your chosen font) exists in your repository
|
20 |
RUN mkdir -p /usr/local/share/fonts/truetype/mycustomfonts
|
21 |
COPY assets/fonts/arial.ttf /usr/local/share/fonts/truetype/mycustomfonts/arial.ttf
|
22 |
-
# If you have other fonts, COPY them here as well:
|
23 |
-
# COPY assets/fonts/anotherfont.ttf /usr/local/share/fonts/truetype/mycustomfonts/anotherfont.ttf
|
24 |
|
25 |
-
# Rebuild font cache
|
26 |
-
RUN fc-cache -f -s -v
|
27 |
|
28 |
# Create a non-root user and group
|
29 |
ARG APP_USER_UID=1000
|
30 |
ARG APP_USER_GID=1000
|
31 |
RUN groupadd --gid $APP_USER_GID appgroup && \
|
32 |
useradd --uid $APP_USER_UID --gid appgroup --shell /bin/bash --create-home appuser
|
|
|
|
|
33 |
|
34 |
-
WORKDIR /home/appuser/app
|
|
|
|
|
35 |
COPY --chown=appuser:appgroup requirements.txt ./
|
|
|
36 |
|
37 |
-
|
|
|
|
|
38 |
RUN python -m pip install --no-cache-dir --upgrade pip
|
39 |
-
RUN python -m pip install --no-cache-dir -r requirements.txt
|
|
|
|
|
|
|
|
|
40 |
|
|
|
41 |
COPY --chown=appuser:appgroup . .
|
42 |
|
43 |
EXPOSE 8501
|
|
|
2 |
|
3 |
# Set environment variables
|
4 |
ENV PYTHONUNBUFFERED=1
|
|
|
5 |
ENV DEBIAN_FRONTEND=noninteractive
|
6 |
+
# Add the default user local bin to PATH. This is where pip often installs executables.
|
7 |
+
ENV PATH="/home/appuser/.local/bin:${PATH}"
|
8 |
|
9 |
# Install system dependencies (ffmpeg, fontconfig for managing copied fonts)
|
10 |
RUN apt-get update && \
|
|
|
17 |
rm -rf /var/lib/apt/lists/*
|
18 |
|
19 |
# Create directory for custom fonts and copy your font file(s)
|
|
|
20 |
RUN mkdir -p /usr/local/share/fonts/truetype/mycustomfonts
|
21 |
COPY assets/fonts/arial.ttf /usr/local/share/fonts/truetype/mycustomfonts/arial.ttf
|
|
|
|
|
22 |
|
23 |
+
# Rebuild font cache
|
24 |
+
RUN fc-cache -f -s -v
|
25 |
|
26 |
# Create a non-root user and group
|
27 |
ARG APP_USER_UID=1000
|
28 |
ARG APP_USER_GID=1000
|
29 |
RUN groupadd --gid $APP_USER_GID appgroup && \
|
30 |
useradd --uid $APP_USER_UID --gid appgroup --shell /bin/bash --create-home appuser
|
31 |
+
# The --create-home flag for useradd usually sets up a basic .profile or .bashrc
|
32 |
+
# which should configure PATH to include ~/.local/bin, but we make it explicit with ENV PATH.
|
33 |
|
34 |
+
WORKDIR /home/appuser/app # This is appuser's home and working directory
|
35 |
+
|
36 |
+
# Copy requirements.txt and install Python dependencies AS APPUSER
|
37 |
COPY --chown=appuser:appgroup requirements.txt ./
|
38 |
+
USER appuser # Switch to appuser BEFORE pip install
|
39 |
|
40 |
+
# Upgrade pip and install Python dependencies
|
41 |
+
# Use python -m pip and specify --user if installing into user's site-packages
|
42 |
+
# However, since WORKDIR is home and we switched user, pip should install to user's .local by default.
|
43 |
RUN python -m pip install --no-cache-dir --upgrade pip
|
44 |
+
RUN python -m pip install --no-cache-dir -r requirements.txt --verbose # Add --verbose for more output
|
45 |
+
|
46 |
+
# Verify streamlit installation location after pip install
|
47 |
+
RUN which streamlit || echo "streamlit not found in PATH after pip install"
|
48 |
+
RUN ls -l /home/appuser/.local/bin || echo "/home/appuser/.local/bin does not exist or is empty"
|
49 |
|
50 |
+
# Copy the rest of the application code as the appuser
|
51 |
COPY --chown=appuser:appgroup . .
|
52 |
|
53 |
EXPOSE 8501
|