Skip to content

🐋 Fully-Dockerised Laravel development in Visual Studio Code

License

Notifications You must be signed in to change notification settings

theomessin/laravel-devcontainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.3-cli-alpine workspace with composer, pgsql, redis, and nodejs.
  • php:8.3-fpm-alpine container with pgsql and redis extensions.
  • nginx:1.27-alpine preconfigured for your Laravel application.
  • postgres:16.3-alpine preconfigured with the default Laravel credentials.
  • redis:7.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 laravel-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 postgres and redis. For example:

DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
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: