Skip to content

Instantly share code, notes, and snippets.

@christopherarter
Created February 16, 2021 13:09
Show Gist options
  • Save christopherarter/588ae9a98b0c7fa736488178cb6ce7f2 to your computer and use it in GitHub Desktop.
Save christopherarter/588ae9a98b0c7fa736488178cb6ce7f2 to your computer and use it in GitHub Desktop.
Laravel Easy Database Docker Compose
version: '3'
services:
laravel_db:
image: mariadb
ports:
- 3306:3306
volumes:
- ./db_data:/var/lib/mysql
environment:
- MYSQL_DATABASE=laravel_db
- MYSQL_ROOT_PASSWORD=root
container_name: laravel_db
#unit testing datbase
laravel_db_test:
image: mariadb
ports:
- 3305:3306
volumes:
- ./db_data_test:/var/lib/mysql
environment:
- MYSQL_DATABASE=laravel_db_test
- MYSQL_ROOT_PASSWORD=root
container_name: laravel_db_test
#caching
cache:
container_name: laravel_cache
image: redis:4.0.11
ports:
- 6379:6379
volumes:
db_data: {}
db_data_test: {}
@christopherarter
Copy link
Author

How to use

  • Download docker desktop download
  • Create a file in your project called docker-compose.yml and paste the content of this gist into that file (and save).
  • Run docker-compose up
  • In your .env file, make sure your credentials match the username (root) and password (root) like this 👇
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=root
DB_PASSWORD=root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment