This article explains how to build a Laravel environment using VS Code's dev container. You can build an environment at high speed as long as you have the tools to use, and since you are using Docker, you can use it as a unified development environment for your team. If you want to move it for the time being, please use the repository link.
https://github.com/naoyayamamoto/laravel-docker-sample Since it is prepared as a template repository, it can also be used as a template.
Use the above tools.
Installation details for
Visual Studio Code are omitted.
Visual Studio Code Remote --Containers is a VS Code plug-in made by Microsoft. You can install it in VS Code from the link.
$ git clone https://github.com/naoyayamamoto/laravel-docker-sample $ code laravel-docker-sample #If you don't have the code command, open the repository with VS Code
Visual Studio Code Remote --Containers, an icon has been added at the bottom left, so press it to open the dialog, or Show All Commands
cmd + shift + Pto open the dialog.
Remote-Containers: Reopen in Containerto start preparing the environment.
http: // localhost: 8000 and you should see the Laravel initial page.
When you open devcontainer, the Docker environment will be built based on
We are using the following containers and will explain each of them.
php artisan serve
.devcontainer/docker/nginx/default.confand send the process to php-fpm
.devcontainer/docker/mysql/my.cnfis loaded (Japanese basic settings)
MYSQL_DATABASE: laravelis set, so no root password, initial table
yarncan be used
.devcontainer/docker/php/php-fpm.d/zzz-www.confto run php-fpm on sock
DB_HOST: dbis set, this is prioritized over the setting in .env and connected to the db container.
The Dockerfile that builds for production has been added to the repository, so please use it as a source of customization. We use a multi-stage build to compile js and install composer in advance to keep the final image as small as possible. I only pass build tests with Github Actions.
For reference, it is a setting when using it with kubernetes. I'm assuming you want to run nginx and php as 1POD.