前提・実現したいこと
https://www.hypertextcandy.com/vue-laravel-tutorial-authentication-part-3/
こちらのサイトを参考にlaravel+vue.jsのサンプルを作っています。
↑に載せた、Vue + Vue Router + Vuex + Laravelで写真共有アプリを作ろう (6) 認証機能とVuexのページ通りの手順で、
php artisan migrateをしたところ、エラーが出てmigrateできないので解決したいです。
環境構築は以下のサイトの、dockerでの開発の手順通り、コピペをして構築しました。
https://www.hypertextcandy.com/vue-laravel-tutorial-setting-up-spa-project/
発生している問題・エラーメッセージ
Illuminate\Database\QueryException : SQLSTATE[08006] [7] could not translate host name "vuesplash_database" to address: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE') vuesplash/web/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669 665| // If an exception occurs when attempting to run a query, we'll format the error 666| // message to include the bindings with SQL, which will make this exception a 667| // lot more helpful to the developer instead of just the database's errors. 668| catch (Exception $e) { > 669| throw new QueryException( 670| $query, $this->prepareBindings($bindings), $e 671| ); 672| } 673| Exception trace: 1 PDOException::("SQLSTATE[08006] [7] could not translate host name "vuesplash_database" to address: nodename nor servname provided, or not known") vuesplash/web/laravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 2 PDO::__construct("pgsql:host=vuesplash_database;dbname=postgres;port=5432;sslmode=prefer", "postgres", "secret", [])
該当のソースコード
以下、関係がありそうなコードです。
.env
.env APP_NAME=Vuesplash APP_ENV=local APP_KEY=base64:96LjyCT7uhviSbV1SvUjM52p9oOgNs9gKlMmjpzc0L4= APP_DEBUG=true APP_URL=http://localhost LOG_CHANNEL=stack DB_CONNECTION=pgsql DB_HOST=vuesplash_database DB_PORT=5432 DB_DATABASE=postgres DB_USERNAME=postgres DB_PASSWORD=secret BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_DRIVER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}" AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET= PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
config/database.php
PHP
1 2 3<?php 4 5use Illuminate\Support\Str; 6 7return [ 8 9/* 10|-------------------------------------------------------------------------- 11| Default Database Connection Name 12|-------------------------------------------------------------------------- 13| 14| Here you may specify which of the database connections below you wish 15| to use as your default connection for all database work. Of course 16| you may use many connections at once using the Database library. 17| 18 */ 19 20 'default' => env('DB_CONNECTION', 'mysql'), 21 22 /* 23 |-------------------------------------------------------------------------- 24 | Database Connections 25 |-------------------------------------------------------------------------- 26 | 27 | Here are each of the database connections setup for your application. 28 | Of course, examples of configuring each database platform that is 29 | supported by Laravel is shown below to make development simple. 30 | 31 | 32 | All database work in Laravel is done through the PHP PDO facilities 33 | so make sure you have the driver for your particular database of 34 | choice installed on your machine before you begin development. 35 | 36 */ 37 38 'connections' => [ 39 40 'sqlite' => [ 41 'driver' => 'sqlite', 42 'url' => env('DATABASE_URL'), 43 'database' => env('DB_DATABASE', database_path('database.sqlite')), 44 'prefix' => '', 45 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 46 ], 47 48 'mysql' => [ 49 'driver' => 'mysql', 50 'url' => env('DATABASE_URL'), 51 'host' => env('DB_HOST', '127.0.0.1'), 52 'port' => env('DB_PORT', '3306'), 53 'database' => env('DB_DATABASE', 'forge'), 54 'username' => env('DB_USERNAME', 'forge'), 55 'password' => env('DB_PASSWORD', ''), 56 'unix_socket' => env('DB_SOCKET', ''), 57 'charset' => 'utf8mb4', 58 'collation' => 'utf8mb4_unicode_ci', 59 'prefix' => '', 60 'prefix_indexes' => true, 61 'strict' => true, 62 'engine' => null, 63 'options' => extension_loaded('pdo_mysql') ? array_filter([ 64 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 65 ]) : [], 66 ], 67 68 'pgsql' => [ 69 'driver' => 'pgsql', 70 'url' => env('DATABASE_URL'), 71 'host' => env('DB_HOST', '127.0.0.1'), 72 'port' => env('DB_PORT', '5432'), 73 'database' => env('DB_DATABASE', 'forge'), 74 'username' => env('DB_USERNAME', 'forge'), 75 'password' => env('DB_PASSWORD', ''), 76 'charset' => 'utf8', 77 'prefix' => '', 78 'prefix_indexes' => true, 79 'schema' => 'public', 80 'sslmode' => 'prefer', 81 ], 82 83 'sqlsrv' => [ 84 'driver' => 'sqlsrv', 85 'url' => env('DATABASE_URL'), 86 'host' => env('DB_HOST', 'localhost'), 87 'port' => env('DB_PORT', '1433'), 88 'database' => env('DB_DATABASE', 'forge'), 89 'username' => env('DB_USERNAME', 'forge'), 90 'password' => env('DB_PASSWORD', ''), 91 'charset' => 'utf8', 92 'prefix' => '', 93 'prefix_indexes' => true, 94 ], 95 96 'sqlite_testing' => [ 97 'driver' => 'sqlite', 98 'database' => ':memory:', 99 'prefix' => '', 100 ], 101 ], 102 103 /* 104 |-------------------------------------------------------------------------- 105 | Migration Repository Table 106 |-------------------------------------------------------------------------- 107 | 108 | This table keeps track of all the migrations that have already run for 109 | your application. Using this information, we can determine which of 110 | the migrations on disk haven't actually been run in the database. 111 | 112 */ 113 114 'migrations' => 'migrations', 115 116 /* 117 |-------------------------------------------------------------------------- 118 | Redis Databases 119 |-------------------------------------------------------------------------- 120 | 121 | Redis is an open source, fast, and advanced key-value store that also 122 | provides a richer body of commands than a typical key-value system 123 | such as APC or Memcached. Laravel makes it easy to dig right in. 124 | 125 */ 126 127 'redis' => [ 128 129 'client' => env('REDIS_CLIENT', 'phpredis'), 130 131 'options' => [ 132 'cluster' => env('REDIS_CLUSTER', 'redis'), 133 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), 134 ], 135 136 'default' => [ 137 'url' => env('REDIS_URL'), 138 'host' => env('REDIS_HOST', '127.0.0.1'), 139 'password' => env('REDIS_PASSWORD', null), 140 'port' => env('REDIS_PORT', '6379'), 141 'database' => env('REDIS_DB', '0'), 142 ], 143 144 'cache' => [ 145 'url' => env('REDIS_URL'), 146 'host' => env('REDIS_HOST', '127.0.0.1'), 147 'password' => env('REDIS_PASSWORD', null), 148 'port' => env('REDIS_PORT', '6379'), 149 'database' => env('REDIS_CACHE_DB', '1'), 150 ], 151 152 ], 153 154]; 155
docker-compose.yml
version: '3' services: vuesplash_web: build: . volumes: - ./web:/var/www/html/vuesplash ports: - 8081:8081 - 3000:3000 vuesplash_database: image: postgres:11-alpine restart: always environment: POSTGRES_PASSWORD: secret volumes: - ./database:/var/lib/postgresql/data ports: - 5434:5432
Dockerfile
FROM php:7.4.1-fpm COPY install-composer.sh / RUN apt-get update \ && apt-get install -y wget git unzip libpq-dev \ && : 'Install Node.js' \ && curl -sL https://deb.nodesource.com/setup_12.x | bash - \ && apt-get install -y nodejs \ && : 'Install PHP Extensions' \ && docker-php-ext-install -j$(nproc) pdo_pgsql \ && : 'Install Composer' \ && chmod 755 /install-composer.sh \ && /install-composer.sh \ && mv composer.phar /usr/local/bin/composer WORKDIR /var/www/html/vuesplash
試したこと
上記のサイトにあるphp artisan migrateまで、すべて同記事内のソースコードをコピペしております。
php artisan migrateまでは特にエラーも出ずスムーズでした。
docker-compose up -d vuesplash_database vuesplash_web
を試し、
docker-compose ps
vuesplash_vuesplash_database_1 docker-entrypoint.sh postgres Up 0.0.0.0:5434->5432/tcp
vuesplash_vuesplash_web_1 docker-php-entrypoint php-fpm Up 0.0.0.0:3000->3000/tcp,
となりましたが、解決はしませんでした。
dockerの再起動も試しましたが、解決しませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/22 14:19