A highly opinionated docker image which aims to be perfectly suited to run our Laravel applications.
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
Create a Dockerfile
with the following contents (and adjust version tag):
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:
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.
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=...
).
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"
Check releases for all notable changes.
The MIT License (MIT). Please see License File for more information.