https://github.com/sourceboat/docker-laravel
A highly opinionated docker image which aims to be perfectly suited to run our Laravel applications.
https://github.com/sourceboat/docker-laravel
docker hacktoberfest laravel php
Last synced: about 1 year ago
JSON representation
A highly opinionated docker image which aims to be perfectly suited to run our Laravel applications.
- Host: GitHub
- URL: https://github.com/sourceboat/docker-laravel
- Owner: sourceboat
- License: mit
- Created: 2019-08-06T11:59:57.000Z (almost 7 years ago)
- Default Branch: develop
- Last Pushed: 2022-12-09T10:01:56.000Z (over 3 years ago)
- Last Synced: 2025-04-05T09:51:08.747Z (about 1 year ago)
- Topics: docker, hacktoberfest, laravel, php
- Language: Dockerfile
- Homepage:
- Size: 147 KB
- Stars: 11
- Watchers: 6
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# `docker-laravel`
[](https://github.com/sourceboat/docker-laravel/releases)
[](https://hub.docker.com/r/sourceboat/docker-laravel/)
[](https://microbadger.com/images/sourceboat/docker-laravel)
A highly opinionated docker image which aims to be perfectly suited to run our Laravel applications.
## What's included?
This Image includes some features to ease the work with Laravel in Docker:
- Tooling and extensions needed for Laravel applications
- Dependency management: Composer, Npm and Yarn
- Datastores: MariaDB, MySQL, Redis
- [Startup commands](#startup-commands)
## Usage
Create a `Dockerfile` with the following contents (and adjust version tag):
```dockerfile
FROM sourceboat/docker-laravel:x.x.x
# install yarn dependencies
COPY package.json yarn.* ./
RUN yarn install --pure-lockfile
# copy application
COPY . ./
# install composer dependencies
RUN composer install -d /opt/app --prefer-dist --no-progress --no-interaction --optimize-autoloader
# create storage symlink
RUN php artisan storage:link
# build assets
RUN yarn production
```
Create a `docker-compose.yml` with the following contents:
```yml
version: '3.7'
services:
app:
build: .
restart: unless-stopped
environment:
- PHP_OPCACHE_VALIDATE_TIMESTAMPS=1
- PHP_MEMORY_LIMIT=1G
- PHP_MAX_EXECUTION_TIME=30
- STARTUP_COMMAND1=/root/modules/dev.sh
- STARTUP_COMMAND2=php artisan migrate --force
- STARTUP_COMMAND3=php artisan setup
volumes:
- ./:/opt/app:cached
ports:
- "8080:8080"
depends_on:
- mysql
mysql:
image: mysql:8.0
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=default"
```
Add more services (e.g. `redis`) if needed.
Make sure to adjust your `.env` accordingly and set `APP_URL` to `http://localhost:8080`.
Run `docker-compose up` to start the services.
### Startup Commands
Further commands can be defined via ENV variable `STARTUP_COMMANDXXX`, which are executed at container start before the actual command.
The commands must be numbered sequentially and start with 1 (e.g. `STARTUP_COMMAND1=command`, `STARTUP_COMMAND2=...`).
```yml
version: '3.7'
services:
app:
image: sourceboat/docker-laravel
restart: unless-stopped
environment:
- PHP_OPCACHE_VALIDATE_TIMESTAMPS=1
- PHP_MEMORY_LIMIT=1G
- PHP_MAX_EXECUTION_TIME=30
- STARTUP_COMMAND1=/root/modules/storage.sh
- STARTUP_COMMAND2=/root/modules/cache.sh
- STARTUP_COMMAND3=php artisan migrate --force
- STARTUP_COMMAND4=php artisan horizon:restart
volumes:
- ./:/opt/app:cached
ports:
- "8080:8080"
depends_on:
- mysql
mysql:
image: mysql:8.0
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=default"
```
## Changelog
Check [releases](https://github.com/sourceboat/docker-laravel/releases) for all notable changes.
## Credits
- [Phil-Bastian Berndt](https://github.com/pehbehbeh)
- [Philipp Kübler](https://github.com/PKuebler)
- [Kevin Buchholz](https://github.com/NeroAzure)
- [Hauke Ingwersen](https://github.com/hingew)
- [All Contributors](https://github.com/sourceboat/docker-laravel/graphs/contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.