136 lines
3.7 KiB
Markdown
136 lines
3.7 KiB
Markdown
# Django Projesi - Docker ile Mevcut PostgreSQL Kullanımı
|
||
|
||
✅ **Projeniz başarıyla dockerize edildi ve çalışıyor!**
|
||
|
||
Bu yapılandırma, mevcut PostgreSQL sunucunuzu (10.80.80.50:5432) kullanarak Django projenizi Docker'da çalıştırır.
|
||
|
||
## 🎉 Test Edildi ve Çalışıyor
|
||
|
||
Server `http://localhost:8000` adresinde çalışıyor!
|
||
|
||
**Oluşturulan Admin Kullanıcısı:**
|
||
- Email: `admin@example.com`
|
||
- Şifre: `admin`
|
||
|
||
## ✅ Yapılan Değişiklikler
|
||
|
||
1. **PostgreSQL Container'ı kaldırıldı** - Mevcut sunucunuz kullanılacak
|
||
2. **[settings.py](core/settings.py)** - Environment değişkenleri ile PostgreSQL yapılandırması
|
||
3. **[docker-compose.yml](docker-compose.yml)** - Sadece web servisi (mevcut PostgreSQL'e bağlanır)
|
||
4. **[docker-compose.prod.yml](docker-compose.prod.yml)** - Production yapılandırması güncellendi
|
||
5. **[entrypoint.sh](entrypoint.sh)** - PostgreSQL bekleme kodu kaldırıldı
|
||
|
||
## 🚀 Kullanım
|
||
|
||
### Geliştirme Ortamı
|
||
|
||
```bash
|
||
# Docker container'ı başlat
|
||
docker-compose up --build
|
||
|
||
# Tarayıcıda aç
|
||
# http://localhost:8000
|
||
```
|
||
|
||
Container otomatik olarak 10.80.80.50:5432 adresindeki PostgreSQL sunucunuza bağlanacak.
|
||
|
||
### Production Ortamı
|
||
|
||
```bash
|
||
# .env dosyasını oluştur
|
||
cp .env.example .env
|
||
|
||
# .env dosyasını düzenle (gerekirse PostgreSQL bilgilerini güncelle)
|
||
|
||
# Production container'ları başlat
|
||
docker-compose -f docker-compose.prod.yml up -d
|
||
```
|
||
|
||
## 🔧 PostgreSQL Bağlantı Ayarları
|
||
|
||
Docker container'ınız şu ayarlarla PostgreSQL'e bağlanır:
|
||
|
||
```
|
||
Host: 10.80.80.50
|
||
Port: 5432
|
||
Database: server_dj
|
||
User: server_dj
|
||
Password: 1234
|
||
```
|
||
|
||
Bu ayarları değiştirmek için:
|
||
|
||
**Geliştirme:** [docker-compose.yml](docker-compose.yml) içindeki environment değişkenlerini düzenleyin
|
||
|
||
**Production:** `.env` dosyasını düzenleyin
|
||
|
||
### SQLite Kullanmak İsterseniz
|
||
|
||
```bash
|
||
# docker-compose.yml içinde USE_POSTGRES değişkenini değiştirin:
|
||
- USE_POSTGRES=False
|
||
```
|
||
|
||
## 📋 Yararlı Komutlar
|
||
|
||
```bash
|
||
# Migration uygula
|
||
docker-compose exec web python manage.py migrate
|
||
|
||
# Superuser oluştur
|
||
docker-compose exec web python manage.py createsuperuser
|
||
|
||
# Shell aç
|
||
docker-compose exec web python manage.py shell
|
||
|
||
# Logları görüntüle
|
||
docker-compose logs -f web
|
||
|
||
# Container'ı durdur
|
||
docker-compose down
|
||
```
|
||
|
||
## 🔍 Sorun Giderme
|
||
|
||
### PostgreSQL'e bağlanamıyorum
|
||
|
||
1. PostgreSQL sunucusunun çalıştığından emin olun
|
||
2. Docker container'ından 10.80.80.50:5432 adresine erişilebildiğini kontrol edin:
|
||
|
||
```bash
|
||
docker-compose exec web bash
|
||
apt-get update && apt-get install -y postgresql-client
|
||
psql -h 10.80.80.50 -U server_dj -d server_dj
|
||
```
|
||
|
||
### Mac'te Docker Network Sorunu
|
||
|
||
Mac'te Docker Desktop kullanıyorsanız ve localhost PostgreSQL'e bağlanamıyorsanız:
|
||
|
||
[docker-compose.yml](docker-compose.yml) içinde:
|
||
```yaml
|
||
environment:
|
||
- POSTGRES_HOST=host.docker.internal # 10.80.80.50 yerine
|
||
```
|
||
|
||
## 📁 Dosya Yapısı
|
||
|
||
```
|
||
.
|
||
├── Dockerfile # Django container image
|
||
├── docker-compose.yml # Geliştirme (mevcut PostgreSQL kullanır)
|
||
├── docker-compose.prod.yml # Production (mevcut PostgreSQL kullanır)
|
||
├── entrypoint.sh # Container başlatma scripti
|
||
├── nginx.conf # Nginx config (production)
|
||
├── .env.example # Environment değişkenleri
|
||
└── core/
|
||
└── settings.py # PostgreSQL ayarları (env değişkenlerinden)
|
||
```
|
||
|
||
## ℹ️ Notlar
|
||
|
||
- Container içinden `10.80.80.50` adresine erişmek için ağ yapılandırmanızın buna izin vermesi gerekir
|
||
- Production ortamında `.env` dosyasındaki şifreleri mutlaka değiştirin
|
||
- İlk çalıştırmada migrations otomatik uygulanır
|
||
- Static dosyalar otomatik toplanır
|