Skip to content

Latest commit

 

History

History
67 lines (50 loc) · 3.85 KB

readme.md

File metadata and controls

67 lines (50 loc) · 3.85 KB

Laravel Development Containers for Visual Studio Code

laravel-devcontainer is a simple configuration to support fully-dockerised development of Laravel applications using Visual Studio Code. Unlike Laravel Sail, laravel-devcontainer has been built so that the entire development experience is dockerised. The only requirements are:

Visual Studio Code will actually run inside a Docker container with php-cli as well as other development tools. Any Extensions will also run in the same container, meaning that intellisense will use the same php-cli configuration!

laravel-devcontainer currently ships with:

  • php:8.0-cli-alpine workspace with composer, mysql, redis, and nodejs.
  • php:8.0-fpm-alpine container with mysql and redis extensions.
  • nginx:1.21-alpine preconfigured for your Laravel application.
  • mysql:8 preconfigured with the default Laravel credentials.
  • redis:6.2-alpine for caching, queues, sessions, etc.

Easy Installation

Using this configuration is quite simple. Download and place laravel-devcontainer in a .devcontainer folder with your Laravel Code. If starting a new project, you may create a new folder with just larave-devcontainer in your .devcontainer folder. You may then install Laravel using Composer (e.g. under example-app). You may then move the .devcontainer folder to your code folder (mv .devcontainer example-app) and use that!

Installing Using Git Submodules

Alternatively, you may use Git Submodules. Install the configuration by running

git submodule add https://github.com/theomessin/laravel-devcontainer .devcontainer

If you use this method, do not forget to install submodules when cloning:

git clone --recurse-submodules ...

Usage

Start Visual Studio Code (e.g. code example-app) and re-open in remote containers (Remote-Containers: Reopen in Container). This may take some time on the first use, as Docker initially downloads and builds the images. Eventually, Visual Studio Code will run inside the workspace container. Extensions and settings specified in devcontainer.json will be auto-configured!

Be sure to correctly configure your application .env to use the devcontainer mysql and redis. For example:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

You may then navigate to localhost on your local machine. Fingers crossed, you will see your Laravel application! Run any artisan or composer commands using the Visual Studio Code Integrated Terminal. As such, you do not need anything else installed on your host machine!

Extensions

laravel-devcontainer currently ships with the following extensions for Laravel development in Visual Studio Code: