"Quick" intro to use Docker in combination with laravel
Slides are available here: https://de.slideshare.net/RenPardon/docker-for-artisans
cd example1 && \
sh run.sh
cd example2 && \
sh run.sh
In addition to the laravel application which gets created through the run.sh script, we created those files and directories:
- docker/web/000-default.conf
- docker/crontab/crontab
- docker/crontab/docker-entrypoint.sh
- .dockerignore
- docker-compose.yml
- Dockerfile
- Dockerfile.dev
- run.sh
I also created an email, event and event listener to demonstrate functionality of the worker container.
cd example3 && \
sh run.sh
The .env file contains a few adjustments to work nicer with the docker environment:
APP_NAME="Docker for Artisans"
APP_URL=http://localhost:8082
LOG_CHANNEL=stderr
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=secret
BROADCAST_DRIVER=redis
CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120
SESSION_ENCRYPT=true
REDIS_HOST=redis
MAIL_DRIVER=smtp
MAIL_HOST=maildev
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_NAME="BoonWeb"
MAIL_FROM_ADDRESS="[email protected]"
Don't use Apache for Worker/Cron containers - it's just useless overhead!
First go into the database container: docker-compose exec db bash
And connect to MariaDB: mysql -uroot -psecret
Then create the database schema: create database laravel;
Now you can run migrations:
docker-compose exec app bash
# Inside the App container:
php artisan queue:table
php artisan migrate
Then open tinker:
php artisan tinker
$mailer = app()->make(Illuminate\Mail\Mailer::class);
$mail = new App\Mail\TestMail();
$mailer->queue($mail);
event(new App\Events\TestEvent);
Just an example with default Dockerfile
:
docker build -t links-der-isar/docker-for-artisans:1.3.945 .