Selamlar, sıfırdan bir proje oluşturup, onu docker üzerine almaya çalışıyorum.
Dockerfile dosyam:
FROM php:8.0-fpm
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install mysqli pdo pdo_mysql
WORKDIR /app
COPY . /app
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8000
EXPOSE 8000
docker-compose dosyam:
version: '3'
services:
app:
build: ./
ports:
- "8000:8000"
environment:
APP_KEY: base64:y8OYMOxKriSnSCKLvMBaB4WwlYd3++Fum703YuJ9ujI=
DB_HOST: mysql
DB_DATABASE: db
DB_USERNAME: laravel
DB_PASSWORD: laravel
DB_PORT: 3306
links:
- mysql
depends_on:
- mysql
mysql:
image: mysql
ports:
- "3306:3306"
expose:
- "3306"
volumes:
- ./server/volumes/mysql:/var/lib/mysql
environment:
MYSQL_USER: laravel
MYSQL_ROOT_PASSWORD: laravel
MYSQL_DATABASE: db
volumes:
mysql:
Sonrasında projeyi build ediyorum:
docker build -t btest12 .
Ardında ayağı kaldırıyorum:
docker run -p 8000:8000 -d btest12
Test etmek için migrate etmeyi denemek istedim. Şu şekilde test ediyorum:
docker exec -it 4f5 bash
burada 4f5 container id
php artisan migrate
Bana döndüğü hata ise şu şekilde:
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = db and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }
Burada nerde hata yapıyorum. Database host isminde mi bir hata var acaba ? Teşekkürler.