Update Dockerfile and docker-compose for /opt/moto_site structure and reliable Docker deployment

This commit is contained in:
ske087
2025-07-29 02:16:43 +03:00
parent 869a032051
commit 5897ed1cbc
5 changed files with 42 additions and 92 deletions

View File

@@ -1,6 +1,8 @@
FROM python:3.11-slim
WORKDIR /opt/site/flask-moto-adventure
# Set working directory for the app
WORKDIR /opt/moto_site
# Install system dependencies
RUN apt-get update && apt-get install -y \
@@ -9,21 +11,27 @@ RUN apt-get update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies
COPY requirements.txt .
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
# Copy all application code to /opt/moto_site
COPY . .
# Create uploads directory
RUN mkdir -p uploads/images uploads/gpx
# Create non-root user
RUN adduser --disabled-password --gecos '' appuser && chown -R appuser:appuser /opt/site/flask-moto-adventure
# Set FLASK_APP so Flask CLI commands are available
ENV FLASK_APP=run.py
# Initialize the database and create admin at build time (as root, before switching user)
RUN flask --app run.py init-db && flask --app run.py create-admin
# Create non-root user and set permissions
RUN adduser --disabled-password --gecos '' appuser && chown -R appuser:appuser /opt/moto_site
USER appuser
# Expose port
EXPOSE 5000
# Run the application with Gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "--timeout", "120", "run:app"]
# Run the application with Gunicorn, looking for run:app in /opt/moto_site
ENTRYPOINT ["/bin/sh", "-c", "exec gunicorn --bind 0.0.0.0:5000 run:app"]