|
| 1 | +# Docker Setup for SCIM Server |
| 2 | + |
| 3 | +This repository includes Docker configuration to run the SCIM server in a containerized environment. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Docker |
| 8 | +- Docker Compose |
| 9 | + |
| 10 | +## Quick Start |
| 11 | + |
| 12 | +1. **Build and start the container:** |
| 13 | + ```bash |
| 14 | + docker-compose up --build |
| 15 | + ``` |
| 16 | + |
| 17 | +2. **Run in background:** |
| 18 | + ```bash |
| 19 | + docker-compose up -d --build |
| 20 | + ``` |
| 21 | + |
| 22 | +3. **Stop the container:** |
| 23 | + ```bash |
| 24 | + docker-compose down |
| 25 | + ``` |
| 26 | + |
| 27 | +## Configuration |
| 28 | + |
| 29 | +### Environment Variables |
| 30 | + |
| 31 | +The following environment variables can be configured in `docker-compose.yml`: |
| 32 | + |
| 33 | +- `PYTHONPATH`: Set to `/app` (default) |
| 34 | +- `LOG_LEVEL`: Set to `info` (default) |
| 35 | + |
| 36 | +### Volumes |
| 37 | + |
| 38 | +The following directories are mounted for persistence: |
| 39 | + |
| 40 | +- `./scim.db` → `/app/scim.db` (main database) |
| 41 | +- `./logs` → `/app/logs` (application logs) |
| 42 | +- `./test_scim.db` → `/app/test_scim.db` (test database) |
| 43 | + |
| 44 | +### Ports |
| 45 | + |
| 46 | +- `7001` - Main SCIM server port |
| 47 | + |
| 48 | +## Health Checks |
| 49 | + |
| 50 | +The container includes robust health checks that verify the application is running properly: |
| 51 | + |
| 52 | +### Basic Health Check |
| 53 | +```bash |
| 54 | +curl http://localhost:7001/healthz |
| 55 | +``` |
| 56 | +Returns: `{"status": "ok", "timestamp": "..."}` |
| 57 | + |
| 58 | +**Access**: Public - accessible from any network |
| 59 | + |
| 60 | +### Detailed Health Check |
| 61 | +```bash |
| 62 | +curl http://localhost:7001/health |
| 63 | +``` |
| 64 | +Returns comprehensive health information including database status. |
| 65 | + |
| 66 | +**Access**: Internal networks only - restricted to: |
| 67 | +- Localhost (127.0.0.1, ::1) |
| 68 | +- Private networks (RFC 1918: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) |
| 69 | +- Docker networks (172.16.0.0/12, 192.168.0.0/16) |
| 70 | +- Link-local addresses (169.254.0.0/16, fe80::/10) |
| 71 | + |
| 72 | +**Security**: The `/health` endpoint is restricted to internal networks for security, while `/healthz` remains publicly accessible for load balancers and external monitoring. |
| 73 | + |
| 74 | +### Health Check Configuration |
| 75 | + |
| 76 | +- **Start Period**: 60 seconds (allows time for application startup) |
| 77 | +- **Interval**: 30 seconds (how often to check) |
| 78 | +- **Timeout**: 10 seconds (timeout for each check) |
| 79 | +- **Retries**: 5 (number of failures before marking unhealthy) |
| 80 | + |
| 81 | +**Note**: Health check endpoints do not require authentication and are designed for Docker health monitoring. |
| 82 | + |
| 83 | +## Development |
| 84 | + |
| 85 | +### Building the Image |
| 86 | + |
| 87 | +```bash |
| 88 | +docker build -t scim-server . |
| 89 | +``` |
| 90 | + |
| 91 | +### Running the Container |
| 92 | + |
| 93 | +```bash |
| 94 | +docker run -p 7001:7001 -v $(pwd)/scim.db:/app/scim.db -v $(pwd)/logs:/app/logs scim-server |
| 95 | +``` |
| 96 | + |
| 97 | +### Viewing Logs |
| 98 | + |
| 99 | +```bash |
| 100 | +# Docker Compose logs |
| 101 | +docker-compose logs -f |
| 102 | + |
| 103 | +# Direct container logs |
| 104 | +docker logs scim-server |
| 105 | +``` |
| 106 | + |
| 107 | +### Checking Health Status |
| 108 | + |
| 109 | +```bash |
| 110 | +# Check container health status |
| 111 | +docker ps |
| 112 | + |
| 113 | +# Check health check logs |
| 114 | +docker inspect scim-server | grep -A 10 "Health" |
| 115 | +``` |
| 116 | + |
| 117 | +## API Endpoints |
| 118 | + |
| 119 | +Once running, the SCIM server will be available at: |
| 120 | + |
| 121 | +- Health Check: `http://localhost:7001/healthz` |
| 122 | +- Detailed Health: `http://localhost:7001/health` |
| 123 | +- SCIM Endpoints: `http://localhost:7001/scim-identifier/{server_id}/scim/v2/` |
| 124 | + |
| 125 | +## Troubleshooting |
| 126 | + |
| 127 | +### Container Won't Start |
| 128 | + |
| 129 | +1. Check if port 7001 is already in use: |
| 130 | + ```bash |
| 131 | + lsof -i :7001 |
| 132 | + ``` |
| 133 | + |
| 134 | +2. Check container logs: |
| 135 | + ```bash |
| 136 | + docker-compose logs |
| 137 | + ``` |
| 138 | + |
| 139 | +3. Check health check status: |
| 140 | + ```bash |
| 141 | + docker ps |
| 142 | + docker inspect scim-server |
| 143 | + ``` |
| 144 | + |
| 145 | +### Health Check Failures |
| 146 | + |
| 147 | +If health checks are failing: |
| 148 | + |
| 149 | +1. Check if the application is starting properly: |
| 150 | + ```bash |
| 151 | + docker-compose logs scim-server |
| 152 | + ``` |
| 153 | + |
| 154 | +2. Test the health endpoint manually: |
| 155 | + ```bash |
| 156 | + curl http://localhost:7001/healthz |
| 157 | + curl http://localhost:7001/health |
| 158 | + ``` |
| 159 | + |
| 160 | +3. Verify the container is running: |
| 161 | + ```bash |
| 162 | + docker exec scim-server ps aux |
| 163 | + ``` |
| 164 | + |
| 165 | +### IP Restriction Issues |
| 166 | + |
| 167 | +If you're getting "Access denied from external network" errors when accessing `/health`: |
| 168 | + |
| 169 | +1. **From Docker container**: The `/health` endpoint is restricted to internal networks only |
| 170 | +2. **From host machine**: Use `localhost` or `127.0.0.1` to access the endpoint |
| 171 | +3. **From external networks**: Use `/healthz` instead, which is publicly accessible |
| 172 | +4. **For monitoring systems**: Configure your monitoring to use `/healthz` for external checks |
| 173 | + |
| 174 | +**Allowed networks for `/health`**: |
| 175 | +- Localhost: `127.0.0.1`, `::1` |
| 176 | +- Private networks: `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16` |
| 177 | +- Docker networks: `172.16.0.0/12`, `192.168.0.0/16` |
| 178 | +- Link-local: `169.254.0.0/16`, `fe80::/10` |
| 179 | + |
| 180 | +### Database Issues |
| 181 | + |
| 182 | +If you encounter database issues, you can reset the database: |
| 183 | + |
| 184 | +1. Stop the container: |
| 185 | + ```bash |
| 186 | + docker-compose down |
| 187 | + ``` |
| 188 | + |
| 189 | +2. Remove the database file: |
| 190 | + ```bash |
| 191 | + rm scim.db |
| 192 | + ``` |
| 193 | + |
| 194 | +3. Restart the container: |
| 195 | + ```bash |
| 196 | + docker-compose up --build |
| 197 | + ``` |
| 198 | + |
| 199 | +### Permission Issues |
| 200 | + |
| 201 | +If you encounter permission issues with mounted volumes, ensure the current user has write permissions to the mounted directories. |
| 202 | + |
| 203 | +## Production Considerations |
| 204 | + |
| 205 | +For production deployment: |
| 206 | + |
| 207 | +1. Use environment-specific configuration |
| 208 | +2. Consider using PostgreSQL instead of SQLite |
| 209 | +3. Set up proper logging and monitoring |
| 210 | +4. Configure SSL/TLS termination |
| 211 | +5. Use secrets management for API keys |
| 212 | +6. Monitor health check metrics |
| 213 | +7. Set up alerting for health check failures |
0 commit comments