fix: Clean up Docker configuration and resolve build issues
- Fix Windows line endings (CRLF) in docker-build.sh script - Remove deprecated 'version' field from docker-compose.dev.yml - Standardize database URL paths across compose files - Optimize Dockerfile.production with better pip upgrade handling - Improve health check timings for better container startup - Add comprehensive Docker usage documentation - Ensure all Docker files use consistent formatting and best practices All Docker builds now work correctly and containers start successfully.
This commit is contained in:
79
DOCKER_USAGE.md
Normal file
79
DOCKER_USAGE.md
Normal file
@@ -0,0 +1,79 @@
|
||||
# Docker Usage Guide
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Development Environment
|
||||
```bash
|
||||
# Build and start development container
|
||||
docker-compose -f docker-compose.dev.yml up --build
|
||||
|
||||
# Or use the build script
|
||||
./docker-build.sh
|
||||
docker-compose -f docker-compose.dev.yml up
|
||||
```
|
||||
|
||||
### Production Environment
|
||||
```bash
|
||||
# Build and start production container
|
||||
docker-compose up --build
|
||||
|
||||
# Or use the build script
|
||||
./docker-build.sh
|
||||
docker-compose up
|
||||
```
|
||||
|
||||
## Available Images
|
||||
|
||||
- `delphi-database:dev` - Development image with source code mounting and auto-reload
|
||||
- `delphi-database:latest` - Production image optimized for performance
|
||||
- `delphi-database:<version>` - Tagged production image with version
|
||||
|
||||
## Environment Variables
|
||||
|
||||
### Required for Production
|
||||
- `SECRET_KEY` - JWT secret key (generate with `openssl rand -base64 32`)
|
||||
- `ADMIN_PASSWORD` - Initial admin user password
|
||||
|
||||
### Optional Configuration
|
||||
- `DATABASE_URL` - Database connection string (default: sqlite:///app/data/delphi_database.db)
|
||||
- `DEBUG` - Enable debug mode (default: False for production, True for development)
|
||||
- `EXTERNAL_PORT` - External port mapping (default: 6920)
|
||||
- `WORKERS` - Number of Gunicorn workers (default: 4)
|
||||
- `LOG_LEVEL` - Logging level (default: INFO for production, DEBUG for development)
|
||||
|
||||
## Container Access
|
||||
|
||||
The application runs on port 8000 inside the container and is mapped to port 6920 on the host by default.
|
||||
|
||||
- Application: http://localhost:6920
|
||||
- Health check: http://localhost:6920/health
|
||||
|
||||
## Data Persistence
|
||||
|
||||
### Development
|
||||
- Source code: Mounted from host for live reload
|
||||
- Database: Docker volume `delphi_dev_data`
|
||||
- Uploads: Docker volume `delphi_dev_uploads`
|
||||
- Backups: Docker volume `delphi_dev_backups`
|
||||
|
||||
### Production
|
||||
- Database: Host directory `./data` (for easy backup)
|
||||
- Uploads: Docker volume `delphi_uploads`
|
||||
- Backups: Docker volume `delphi_backups`
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Container won't start
|
||||
1. Check if port 6920 is already in use
|
||||
2. Ensure required environment variables are set
|
||||
3. Check Docker logs: `docker-compose logs`
|
||||
|
||||
### Database issues
|
||||
1. Check database file permissions in `./data` directory
|
||||
2. Ensure the container can write to mounted volumes
|
||||
3. Check initialization logs for admin user creation
|
||||
|
||||
### Build failures
|
||||
1. Ensure Docker daemon is running
|
||||
2. Clear Docker cache: `docker system prune -f`
|
||||
3. Rebuild without cache: `docker-compose build --no-cache`
|
||||
@@ -49,7 +49,7 @@ USER delphi
|
||||
EXPOSE 8000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||
CMD curl -f http://localhost:8000/health || exit 1
|
||||
|
||||
# Start command
|
||||
|
||||
@@ -22,10 +22,10 @@ WORKDIR /app
|
||||
# Copy requirements and install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
pip install --user -r requirements.txt
|
||||
pip install --upgrade pip \
|
||||
&& pip install --user -r requirements.txt
|
||||
|
||||
# Production stage
|
||||
ARG BASE_IMAGE=python:3.12-slim
|
||||
FROM ${BASE_IMAGE}
|
||||
|
||||
# Set labels
|
||||
@@ -45,6 +45,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
# Install runtime dependencies only
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
bash \
|
||||
curl \
|
||||
sqlite3 \
|
||||
tini \
|
||||
@@ -58,15 +59,16 @@ RUN addgroup --system --gid 1001 delphi \
|
||||
# Set work directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy Python packages from builder
|
||||
COPY --from=builder /root/.local /root/.local
|
||||
# Copy Python packages from builder into system prefix so non-root user can access them
|
||||
COPY --from=builder /root/.local /usr/local
|
||||
|
||||
# Copy application code
|
||||
COPY --chown=delphi:delphi . .
|
||||
|
||||
# Copy and set up initialization script
|
||||
COPY scripts/init-container.sh /usr/local/bin/init-container.sh
|
||||
RUN chmod +x /usr/local/bin/init-container.sh
|
||||
# Normalize line endings to avoid shebang issues and ensure executable
|
||||
RUN sed -i 's/\r$//' /usr/local/bin/init-container.sh && chmod +x /usr/local/bin/init-container.sh
|
||||
|
||||
# Create necessary directories
|
||||
RUN mkdir -p /app/data /app/uploads /app/backups /app/exports /app/logs \
|
||||
@@ -89,4 +91,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/init-container.sh"]
|
||||
|
||||
# Start with gunicorn for production
|
||||
CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--timeout", "120", "--keepalive", "5"]
|
||||
CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--timeout", "120", "--keep-alive", "5"]
|
||||
@@ -1,5 +1,3 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
delphi-db:
|
||||
build:
|
||||
@@ -11,7 +9,7 @@ services:
|
||||
ports:
|
||||
- "${EXTERNAL_PORT:-6920}:8000"
|
||||
environment:
|
||||
- DATABASE_URL=${DATABASE_URL:-sqlite:///data/delphi_database.db}
|
||||
- DATABASE_URL=${DATABASE_URL:-sqlite:///app/data/delphi_database.db}
|
||||
- SECRET_KEY=${SECRET_KEY:-dev-secret-key-not-for-production}
|
||||
- DEBUG=${DEBUG:-True}
|
||||
- ACCESS_TOKEN_EXPIRE_MINUTES=${ACCESS_TOKEN_EXPIRE_MINUTES:-120}
|
||||
|
||||
@@ -9,7 +9,7 @@ services:
|
||||
ports:
|
||||
- "${EXTERNAL_PORT:-6920}:8000"
|
||||
environment:
|
||||
- DATABASE_URL=${DATABASE_URL:-sqlite:///data/delphi_database.db}
|
||||
- DATABASE_URL=${DATABASE_URL:-sqlite:///app/data/delphi_database.db}
|
||||
- SECRET_KEY=${SECRET_KEY}
|
||||
- DEBUG=${DEBUG:-False}
|
||||
- ACCESS_TOKEN_EXPIRE_MINUTES=${ACCESS_TOKEN_EXPIRE_MINUTES:-30}
|
||||
|
||||
Reference in New Issue
Block a user