teleapi / Dockerfile
BinaryONe
Nginx Changes
e95fa34
raw
history blame
2.09 kB
FROM alpine:latest
# Install system dependencies, including shadow-utils for adduser
RUN apk update && apk upgrade && \
apk add --no-cache nginx python3 python3-dev py3-pip build-base libffi-dev openssl-dev shadow gcc musl-dev
# Install python/pip
#ENV PYTHONUNBUFFERED=1
#RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
#RUN python3 -m ensurepip
#RUN pip3 install --no-cache --upgrade pip setuptools
# Create a group and user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Set working directory for the application
WORKDIR /app
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Copy only the necessary files first for better cache utilization
COPY requirements.txt /app/requirements.txt
# Copy the rest of the application code after installing dependencies for better cache
COPY . /app
# Create a virtual environment within the container
#RUN python3 -m venv /app/venv
# Create and activate the virtual environment AND install requirements in ONE RUN command
RUN python3 -m venv /app/venv && \
/app/venv/bin/pip install --no-cache-dir --upgrade pip && \
/app/venv/bin/pip install --no-cache-dir -r /app/requirements.txt
#Before
RUN python --version && pip3 list
# Activate the virtual environment (important!)
RUN source /app/venv/bin/activate
RUN pip install --no-cache-dir -r /app/requirements.txt
#After
RUN python --version && pip3 list
# Install Python dependencies from the requirements file within the virtual environment
#RUN py3-pip install --no-cache-dir --upgrade -r requirements.txt
#RUN pip install -r requirements.txt
# Create necessary directories and set correct permissions
RUN mkdir -p /var/www/html /var/log/nginx && \
chown -R nginx:nginx /var/log/nginx && \
chown -R appuser:appgroup /app /var/www/html /var/log/nginx
# Set ownership of the app directory
#RUN chown -R appuser:appgroup /app
# Switch to the non-root user
USER appuser
EXPOSE 7860
# Start Nginx and the AIOHTTP app (using exec for proper signal handling)
CMD ["sh", "-c", "exec python -u -m FileStream & nginx -g 'daemon off;'"]