前提
DockerやVisual Studio Codeなどはインストール済みと仮定する。
プロジェクトの作成
適当なディレクトリで以下を実行すると、example-appディレクトリ内にlaravelのアプリが作成される。
curl -s "https://laravel.build/example-app?with=mysql,redis&devcontainer" | bash
ポイントは、&devcontainer
の部分で、これを指定すると、.devcontainer/devcotainer.json
が自動で作成される。
with
クエリでは、mysql,redis,meilisearch,mailpit,selenium
などが選択可能。
途中でパスワードの入力が求められる。
devcontainerの立ち上げ
example-app
ディレクトリをVisual Studio Codeで開き、コマンドパレットからDev Containers: Rebuild and Reopen in Container
を選択して、Docker環境が立ち上がる。
サーバーの立ち上げ
コンテナ内で以下を実行することで、サーバーが立ち上がるはずである。
php artisan serve