Docker functionality
This commit is contained in:
176
README-Docker.md
Normal file
176
README-Docker.md
Normal file
@@ -0,0 +1,176 @@
|
||||
# Jobs App - Docker Deployment
|
||||
|
||||
This application is a Craigslist job scraper with a Flask web interface.
|
||||
|
||||
## Quick Start with Docker
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Docker
|
||||
- Docker Compose
|
||||
|
||||
### Deployment
|
||||
|
||||
1. **Clone the repository and navigate to the project directory**
|
||||
|
||||
```bash
|
||||
cd /path/to/jobs-app/jobs
|
||||
```
|
||||
|
||||
2. **Start the application**
|
||||
|
||||
```bash
|
||||
docker-compose up --build -d
|
||||
```
|
||||
|
||||
3. **Wait for services to be ready** (about 30 seconds)
|
||||
|
||||
```bash
|
||||
# Check if the app is running
|
||||
curl http://localhost:8000
|
||||
```
|
||||
|
||||
4. **Access the application**
|
||||
- Main app: http://localhost:8000
|
||||
- Admin interface: http://localhost:8000/admin/users
|
||||
- Username: `admin`
|
||||
- Password: `M11ffpgm.`
|
||||
- Scraper interface: http://localhost:8000/scrape-page
|
||||
|
||||
## Docker Architecture
|
||||
|
||||
### Services
|
||||
|
||||
- **jobs-app**: Flask application with Gunicorn WSGI server
|
||||
- **mysql**: MySQL 8.0 database
|
||||
|
||||
### Ports
|
||||
|
||||
- 8000: Flask application
|
||||
- 3306: MySQL database (exposed for external access if needed)
|
||||
|
||||
### Volumes
|
||||
|
||||
- `mysql_data`: Persistent MySQL data storage
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
|
||||
- `FLASK_ENV`: Set to `production`
|
||||
- `FLASK_SECRET`: Secret key for Flask sessions
|
||||
|
||||
### Database Configuration
|
||||
|
||||
The database configuration is in `config/settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"database": {
|
||||
"mysql": {
|
||||
"host": "mysql",
|
||||
"user": "jobs",
|
||||
"password": "jobdb",
|
||||
"database": "jobs",
|
||||
"port": 3306
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Useful Commands
|
||||
|
||||
```bash
|
||||
# View logs
|
||||
docker-compose logs -f
|
||||
|
||||
# Stop services
|
||||
docker-compose down
|
||||
|
||||
# Restart services
|
||||
docker-compose restart
|
||||
|
||||
# Rebuild and restart
|
||||
docker-compose up --build
|
||||
|
||||
# View running containers
|
||||
docker-compose ps
|
||||
|
||||
# Execute commands in the app container
|
||||
docker-compose exec jobs-app bash
|
||||
|
||||
# Check database
|
||||
docker-compose exec mysql mysql -u jobs -p jobs
|
||||
```
|
||||
|
||||
## Production Considerations
|
||||
|
||||
1. **Security**:
|
||||
|
||||
- Change default passwords in `docker-compose.yml`
|
||||
- Use environment variables for secrets
|
||||
- Configure proper firewall rules
|
||||
|
||||
2. **Scaling**:
|
||||
|
||||
- Adjust Gunicorn workers in `gunicorn.conf.py`
|
||||
- Consider using a reverse proxy (nginx)
|
||||
- Implement proper logging and monitoring
|
||||
|
||||
3. **Database**:
|
||||
|
||||
- Use external MySQL for production
|
||||
- Configure backups
|
||||
- Set up connection pooling
|
||||
|
||||
4. **Networking**:
|
||||
- Use proper domain names
|
||||
- Configure SSL/TLS
|
||||
- Set up load balancing if needed
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Port conflicts**: Change ports in `docker-compose.yml`
|
||||
2. **Database connection**: Ensure MySQL container is healthy
|
||||
3. **Memory issues**: Increase Docker memory limits
|
||||
4. **Permission issues**: Check file permissions in mounted volumes
|
||||
|
||||
### Logs
|
||||
|
||||
```bash
|
||||
# Application logs
|
||||
docker-compose logs jobs-app
|
||||
|
||||
# Database logs
|
||||
docker-compose logs mysql
|
||||
|
||||
# All logs
|
||||
docker-compose logs
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
For development with hot reload:
|
||||
|
||||
```bash
|
||||
# Run in development mode
|
||||
docker-compose -f docker-compose.dev.yml up --build
|
||||
```
|
||||
|
||||
Create `docker-compose.dev.yml`:
|
||||
|
||||
```yaml
|
||||
version: "3.8"
|
||||
services:
|
||||
jobs-app:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
environment:
|
||||
- FLASK_ENV=development
|
||||
volumes:
|
||||
- .:/app
|
||||
command: ["flask", "run", "--host", "0.0.0.0", "--port", "8000"]
|
||||
```
|
||||
Reference in New Issue
Block a user