Laravel SailでMySQLからPostgresに変更する方法

Laravelの環境をDockerで立ち上げるのに便利なLaravel Sailですが、同時に立ち上げるサービスを指定することができるようです。

Laravel Sail

Laravel Sailは Laravel に同梱されたDockerの開発環境を操作するためのコマンドです。
自前でDockerfileやdocker-compose.ymlを用意することなくローカル環境の構築が可能です。
また、artisanコマンドをラップしているため、コンテナを意識することなく操作することが可能となっています。

起動するサービスの一覧

公式ドキュメントの Installation & Setup を行った際に立ち上がるサービスは以下の6点です。

  • Laravel (PHP)
  • MySQL
  • Selenium
  • MailHog
  • Redis
  • MeiliSearch

サービスをもう少し減らしたい & MySQLをPostgresに変更したいという要望はありそうですが、ちゃんとそのあたりのカスタマイズもできるようになっています。

MySQLからPostgresに変更する

以下でできます。

$ sail artisan sail:install --with=pgsql

artisanコマンドに sail:install が追加されているので、ヘルプを見てみると良いでしょう。

$ sail artisan help sail:install
Description:
  Install Laravel Sail's default Docker Compose file

Usage:
  sail:install [options]

Options:
      --with[=WITH]     The services that should be included in the installation
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

--with オプションで追加できるサービスは /vendor/laravel/sail/src/Console/InstallCommand.php に記載されていました。

/**
 * Gather the desired Sail services using a Symfony menu.
 *
 * @return array
 */
protected function gatherServicesWithSymfonyMenu()
{
    return $this->choice('Which services would you like to install?', [
         'mysql',
         'pgsql',
         'redis',
         'memcached',
         'meilisearch',
         'mailhog',
         'selenium',
     ], 0, null, true);
}
タイトルとURLをコピーしました