first commit
This commit is contained in:
227
DOCKER_README.md
Normal file
227
DOCKER_README.md
Normal file
@@ -0,0 +1,227 @@
|
||||
# Django Projesi - Docker Kurulum Rehberi
|
||||
|
||||
Bu Django projesi Python 3.14.2 ile dockerize edilmiştir.
|
||||
|
||||
## 📋 Gereksinimler
|
||||
|
||||
- Docker
|
||||
- Docker Compose
|
||||
|
||||
## 🚀 Hızlı Başlangıç
|
||||
|
||||
### Geliştirme Ortamı (Development)
|
||||
|
||||
1. **Projeyi klonlayın ve dizine girin:**
|
||||
```bash
|
||||
cd /path/to/project
|
||||
```
|
||||
|
||||
2. **Docker container'ları başlatın:**
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
3. **Tarayıcınızda açın:**
|
||||
```
|
||||
http://localhost:8000
|
||||
```
|
||||
|
||||
### Production Ortamı
|
||||
|
||||
1. **Environment dosyasını oluşturun:**
|
||||
```bash
|
||||
cp .env.example .env
|
||||
# .env dosyasını düzenleyin ve gerçek değerleri girin
|
||||
```
|
||||
|
||||
2. **Production container'ları başlatın:**
|
||||
```bash
|
||||
docker-compose -f docker-compose.prod.yml up --build -d
|
||||
```
|
||||
|
||||
3. **Nginx üzerinden erişin:**
|
||||
```
|
||||
http://localhost
|
||||
```
|
||||
|
||||
## 🛠️ Yararlı Komutlar
|
||||
|
||||
### Container'ları Başlatma
|
||||
```bash
|
||||
# Geliştirme
|
||||
docker-compose up
|
||||
|
||||
# Production
|
||||
docker-compose -f docker-compose.prod.yml up -d
|
||||
|
||||
# Rebuild ile başlatma
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
### Container'ları Durdurma
|
||||
```bash
|
||||
docker-compose down
|
||||
|
||||
# Volume'leri de silmek için
|
||||
docker-compose down -v
|
||||
```
|
||||
|
||||
### Django Komutları Çalıştırma
|
||||
```bash
|
||||
# Migration oluşturma
|
||||
docker-compose exec web python manage.py makemigrations
|
||||
|
||||
# Migration uygulama
|
||||
docker-compose exec web python manage.py migrate
|
||||
|
||||
# Superuser oluşturma
|
||||
docker-compose exec web python manage.py createsuperuser
|
||||
|
||||
# Shell açma
|
||||
docker-compose exec web python manage.py shell
|
||||
|
||||
# Static dosyaları toplama
|
||||
docker-compose exec web python manage.py collectstatic
|
||||
```
|
||||
|
||||
### Celery Komutları
|
||||
```bash
|
||||
# Celery worker loglarını görüntüleme
|
||||
docker-compose logs -f celery
|
||||
|
||||
# Production ortamında
|
||||
docker-compose -f docker-compose.prod.yml logs -f celery-atahan
|
||||
|
||||
# Celery worker'ı yeniden başlatma
|
||||
docker-compose restart celery
|
||||
|
||||
# Celery container'a bağlanma
|
||||
docker-compose exec celery bash
|
||||
|
||||
# Celery task durumlarını kontrol etme (Django shell içinde)
|
||||
docker-compose exec web python manage.py shell
|
||||
# >>> from django_celery_results.models import TaskResult
|
||||
# >>> TaskResult.objects.all()
|
||||
```
|
||||
|
||||
### Logları Görüntüleme
|
||||
```bash
|
||||
# Tüm servislerin logları
|
||||
docker-compose logs -f
|
||||
|
||||
# Sadece web servisinin logları
|
||||
docker-compose logs -f web
|
||||
|
||||
# Sadece database logları
|
||||
docker-compose logs -f db
|
||||
```
|
||||
|
||||
### Container'a Bağlanma
|
||||
```bash
|
||||
# Web container'a bash ile bağlan
|
||||
docker-compose exec web bash
|
||||
|
||||
# Database container'a bağlan
|
||||
docker-compose exec db psql -U server_dj -d server_dj
|
||||
```
|
||||
|
||||
## 📁 Proje Yapısı
|
||||
|
||||
```
|
||||
.
|
||||
├── Dockerfile # Ana Docker image tanımı
|
||||
├── docker-compose.yml # Geliştirme ortamı yapılandırması
|
||||
├── docker-compose.prod.yml # Production ortamı yapılandırması
|
||||
├── entrypoint.sh # Container başlatma scripti
|
||||
├── nginx.conf # Nginx yapılandırması (production)
|
||||
├── .dockerignore # Docker'a dahil edilmeyecek dosyalar
|
||||
├── .env.example # Environment değişkenleri şablonu
|
||||
└── requirements.txt # Python bağımlılıkları
|
||||
```
|
||||
|
||||
## 🔧 Konfigürasyon
|
||||
|
||||
### Environment Değişkenleri
|
||||
|
||||
`.env` dosyasında aşağıdaki değişkenleri ayarlayabilirsiniz:
|
||||
|
||||
- `DEBUG`: Debug modu (0 veya 1)
|
||||
- `SECRET_KEY`: Django secret key
|
||||
- `DJANGO_ALLOWED_HOSTS`: İzin verilen host'lar
|
||||
- `POSTGRES_DB`: PostgreSQL veritabanı adı
|
||||
- `POSTGRES_USER`: PostgreSQL kullanıcı adı
|
||||
- `POSTGRES_PASSWORD`: PostgreSQL şifresi
|
||||
|
||||
### Veritabanı
|
||||
|
||||
Proje hem SQLite hem de PostgreSQL destekler:
|
||||
|
||||
- **Development**: SQLite (varsayılan)
|
||||
- **Production**: PostgreSQL (docker-compose ile)
|
||||
|
||||
### Static ve Media Dosyaları
|
||||
|
||||
- Static dosyalar: `/app/staticfiles`
|
||||
- Media dosyaları: `/app/media`
|
||||
- Her ikisi de Docker volume'lerinde saklanır
|
||||
|
||||
## 🔐 Güvenlik
|
||||
|
||||
Production ortamında:
|
||||
|
||||
1. `.env` dosyasındaki tüm varsayılan şifreleri değiştirin
|
||||
2. `SECRET_KEY` için güçlü bir değer kullanın
|
||||
3. `DEBUG=0` olarak ayarlayın
|
||||
4. `ALLOWED_HOSTS` değerini doğru domain ile güncelleyin
|
||||
5. SSL sertifikası ekleyin (nginx yapılandırmasına)
|
||||
|
||||
## 📊 Veritabanı Yedekleme
|
||||
|
||||
### PostgreSQL Backup
|
||||
```bash
|
||||
# Backup alma
|
||||
docker-compose exec db pg_dump -U server_dj server_dj > backup.sql
|
||||
|
||||
# Backup geri yükleme
|
||||
docker-compose exec -T db psql -U server_dj server_dj < backup.sql
|
||||
```
|
||||
|
||||
## 🐛 Sorun Giderme
|
||||
|
||||
### Port zaten kullanımda
|
||||
```bash
|
||||
# Port 8000'i kullanan process'i bul
|
||||
lsof -i :8000
|
||||
|
||||
# Veya farklı port kullan
|
||||
# docker-compose.yml'de ports kısmını değiştirin
|
||||
```
|
||||
|
||||
### Container başlamıyor
|
||||
```bash
|
||||
# Logları kontrol et
|
||||
docker-compose logs web
|
||||
|
||||
# Container'ları temizle ve yeniden başlat
|
||||
docker-compose down -v
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
### Static dosyalar yüklenmiyor
|
||||
```bash
|
||||
# Static dosyaları yeniden topla
|
||||
docker-compose exec web python manage.py collectstatic --noinput --clear
|
||||
```
|
||||
|
||||
## 📝 Notlar
|
||||
|
||||
- İlk çalıştırmada `entrypoint.sh` otomatik olarak:
|
||||
- Database migration'larını uygular
|
||||
- Admin kullanıcısı oluşturur (admin/admin)
|
||||
- Static dosyaları toplar
|
||||
|
||||
- Development ortamında kod değişiklikleri otomatik olarak yansır (volume mount sayesinde)
|
||||
|
||||
## 📞 Destek
|
||||
|
||||
Herhangi bir sorun için issue açabilirsiniz.
|
||||
Reference in New Issue
Block a user