├── .env.example ├── cli └── Dockerfile ├── devcontainer.json ├── docker-compose.yaml ├── fpm └── Dockerfile ├── license.md ├── nginx ├── Dockerfile └── default.conf └── readme.md /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | LOG_CHANNEL=stack 8 | LOG_LEVEL=debug 9 | 10 | DB_CONNECTION=pgsql 11 | DB_HOST=postgres 12 | DB_PORT=5432 13 | DB_DATABASE=laravel 14 | DB_USERNAME=root 15 | DB_PASSWORD= 16 | 17 | BROADCAST_DRIVER=log 18 | CACHE_DRIVER=redis 19 | FILESYSTEM_DRIVER=local 20 | QUEUE_CONNECTION=redis 21 | SESSION_DRIVER=redis 22 | SESSION_LIFETIME=120 23 | 24 | MEMCACHED_HOST=127.0.0.1 25 | 26 | REDIS_HOST=redis 27 | REDIS_PASSWORD=null 28 | REDIS_PORT=6379 29 | 30 | MAIL_MAILER=smtp 31 | MAIL_HOST=mailhog 32 | MAIL_PORT=1025 33 | MAIL_USERNAME=null 34 | MAIL_PASSWORD=null 35 | MAIL_ENCRYPTION=null 36 | MAIL_FROM_ADDRESS=null 37 | MAIL_FROM_NAME="${APP_NAME}" 38 | 39 | AWS_ACCESS_KEY_ID= 40 | AWS_SECRET_ACCESS_KEY= 41 | AWS_DEFAULT_REGION=us-east-1 42 | AWS_BUCKET= 43 | AWS_USE_PATH_STYLE_ENDPOINT=false 44 | 45 | PUSHER_APP_ID= 46 | PUSHER_APP_KEY= 47 | PUSHER_APP_SECRET= 48 | PUSHER_APP_CLUSTER=mt1 49 | 50 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 51 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 52 | -------------------------------------------------------------------------------- /cli/Dockerfile: -------------------------------------------------------------------------------- 1 | # From official php image. 2 | FROM php:8.3-cli-alpine 3 | # Create a user group and account under id 1000. 4 | RUN addgroup -g 1000 -S user && adduser -u 1000 -D user -G user 5 | # Install quality-of-life packages. 6 | RUN apk add --no-cache bash curl git vim 7 | # Install composer for php deps. 8 | RUN apk add --no-cache composer 9 | # Composer uses its php binary, but we want it to use the container's one 10 | RUN rm -f /usr/bin/php83 11 | RUN ln -s /usr/local/bin/php /usr/bin/php83 12 | # Install postgres pdo driver. 13 | RUN apk add --no-cache postgresql-dev && docker-php-ext-install pdo_pgsql 14 | # Install redis driver. 15 | RUN mkdir -p /usr/src/php/ext/redis; \ 16 | curl -fsSL --ipv4 https://github.com/phpredis/phpredis/archive/6.0.2.tar.gz | tar xvz -C "/usr/src/php/ext/redis" --strip 1; \ 17 | docker-php-ext-install redis 18 | # Install nodejs and npm for frontend. 19 | RUN apk add --no-cache nodejs npm 20 | # Prevent container from exiting early. 21 | CMD ["sleep", "infinity"] 22 | -------------------------------------------------------------------------------- /devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Laravel", 3 | "service": "cli", 4 | "remoteUser": "user", 5 | "shutdownAction": "stopCompose", 6 | "workspaceFolder": "/workspaces/laravel", 7 | "dockerComposeFile": "docker-compose.yaml", 8 | "customizations": { 9 | "vscode": { 10 | "extensions": [ 11 | "bmewburn.vscode-intelephense-client", 12 | "eamodio.gitlens", 13 | "EditorConfig.EditorConfig", 14 | "mikestead.dotenv", 15 | "onecentlin.laravel-blade" 16 | ] 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3.9" 2 | services: 3 | cli: 4 | build: cli 5 | volumes: 6 | - ..:/workspaces/laravel 7 | 8 | fpm: 9 | build: fpm 10 | volumes: 11 | - ..:/workspaces/laravel 12 | user: 1000:1000 13 | 14 | nginx: 15 | build: nginx 16 | volumes: 17 | - ..:/workspaces/laravel 18 | ports: 19 | - 80:80 20 | depends_on: 21 | - fpm 22 | 23 | postgres: 24 | image: postgres:16.3-alpine 25 | environment: 26 | POSTGRES_DB: laravel 27 | POSTGRES_USER: root 28 | POSTGRES_HOST_AUTH_METHOD: trust 29 | 30 | redis: 31 | image: redis:7.2-alpine 32 | -------------------------------------------------------------------------------- /fpm/Dockerfile: -------------------------------------------------------------------------------- 1 | # From official php image. 2 | FROM php:8.3-fpm-alpine 3 | # Install postgres pdo driver. 4 | RUN apk add --no-cache postgresql-dev && docker-php-ext-install pdo_pgsql 5 | # Install redis driver. 6 | RUN mkdir -p /usr/src/php/ext/redis; \ 7 | curl -fsSL --ipv4 https://github.com/phpredis/phpredis/archive/6.0.2.tar.gz | tar xvz -C "/usr/src/php/ext/redis" --strip 1; \ 8 | docker-php-ext-install redis 9 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Theodore Messinezis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.27-alpine 2 | COPY default.conf /etc/nginx/conf.d/default.conf 3 | -------------------------------------------------------------------------------- /nginx/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name localhost; 4 | root /workspaces/laravel/public; 5 | 6 | add_header X-Frame-Options "SAMEORIGIN"; 7 | add_header X-Content-Type-Options "nosniff"; 8 | 9 | index index.php; 10 | 11 | charset utf-8; 12 | 13 | location / { 14 | try_files $uri $uri/ /index.php?$query_string; 15 | } 16 | 17 | location = /favicon.ico { access_log off; log_not_found off; } 18 | location = /robots.txt { access_log off; log_not_found off; } 19 | 20 | error_page 404 /index.php; 21 | 22 | location ~ \.php$ { 23 | fastcgi_pass fpm:9000; 24 | fastcgi_index index.php; 25 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 26 | fastcgi_param PHP_VALUE "error_log=/var/log/nginx/php_errors.log"; 27 | fastcgi_buffers 16 16k; 28 | fastcgi_buffer_size 32k; 29 | include fastcgi_params; 30 | } 31 | 32 | location ~ /\.(?!well-known).* { 33 | deny all; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ### Laravel Development Containers for Visual Studio Code 2 | 3 | `laravel-devcontainer` is a simple configuration to support fully-dockerised development of Laravel applications using Visual Studio Code. 4 | Unlike Laravel Sail, `laravel-devcontainer` has been built so that the entire development experience is dockerised. The only requirements are: 5 | 6 | - [Visual Studio Code](https://code.visualstudio.com/) 7 | - [Visual Studio Code Remote Containers Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) 8 | - [Docker](https://docs.docker.com/get-docker/) 9 | - [Docker Compose](https://docs.docker.com/compose/install/) 10 | 11 | Visual Studio Code will actually run inside a Docker container with php-cli as well as other development tools. 12 | Any Extensions will also run in the same container, meaning that intellisense will use the same php-cli configuration! 13 | 14 | `laravel-devcontainer` currently ships with: 15 | 16 | - `php:8.3-cli-alpine` workspace with composer, pgsql, redis, and nodejs. 17 | - `php:8.3-fpm-alpine` container with pgsql and redis extensions. 18 | - `nginx:1.27-alpine` preconfigured for your Laravel application. 19 | - `postgres:16.3-alpine` preconfigured with the default Laravel credentials. 20 | - `redis:7.2-alpine` for caching, queues, sessions, etc. 21 | 22 | #### Easy Installation 23 | 24 | Using this configuration is quite simple. [Download](https://github.com/theomessin/laravel-devcontainer/archive/refs/heads/master.zip) 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](https://laravel.com/docs/11.x/installation#creating-a-laravel-project) (e.g. under `example-app`). You may then move the `.devcontainer` folder to your code folder (`mv .devcontainer example-app`) and use that! 25 | 26 | #### Installing Using Git Submodules 27 | 28 | Alternatively, you may use [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). Install the configuration by running 29 | 30 | ```sh 31 | git submodule add https://github.com/theomessin/laravel-devcontainer .devcontainer 32 | ``` 33 | 34 | If you use this method, do not forget to install submodules when cloning: 35 | 36 | ``` 37 | git clone --recurse-submodules ... 38 | ``` 39 | 40 | #### Usage 41 | 42 | 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! 43 | 44 | Be sure to correctly configure your application `.env` to use the devcontainer postgres and redis. For example: 45 | 46 | ```env 47 | DB_CONNECTION=pgsql 48 | DB_HOST=postgres 49 | DB_PORT=5432 50 | DB_DATABASE=laravel 51 | DB_USERNAME=root 52 | DB_PASSWORD= 53 | 54 | REDIS_HOST=redis 55 | REDIS_PASSWORD=null 56 | REDIS_PORT=6379 57 | ``` 58 | 59 | You may then navigate to [`localhost`](http://localhost) on your local machine. Fingers crossed, you will see your Laravel application! 60 | Run any artisan or composer commands using the Visual Studio Code [Integrated Terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). 61 | As such, you do not need anything else installed on your host machine! 62 | 63 | #### Extensions 64 | 65 | `laravel-devcontainer` currently ships with the following extensions for Laravel development in Visual Studio Code: 66 | 67 | - ["bmewburn.vscode-intelephense-client"](https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client) 68 | - ["eamodio.gitlens"](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) 69 | - ["EditorConfig.EditorConfig"](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig) 70 | - ["mikestead.dotenv"](https://marketplace.visualstudio.com/items?itemName=mikestead.dotenv) 71 | - ["onecentlin.laravel-blade"](https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-blade) 72 | --------------------------------------------------------------------------------