Docker Compose
Outline
- Why
- Implement
- run a database
- run a web server
- serve a Laravel app
- connect to database
- Recap
- Cheat Sheet
Why Docker Compose
- Can have different apps require different enviroments on local machine. For example, one app use php5, the other use php7.
- Portible enviroment setup of yout app
- Keep local machine clean. For example, install Composer in container instead of local machine
Implement
clone thise repo
Run A Database
Let's run a MySQL database with phpMyAdmin
go to localhost:8888 check if the database is up
Run A Web Server
go to localhost:4444 check if the website served
Run a Laravel App
Remap Nginx serve path to example-app
. Edit docker-compose.yml
Recreate the container
go to localhost:4444 check if the Laravel app served
Laravel App Connect To DB
-
Create a database. (we can use phpMyAdmin or go into container use CLI)
-
edit .env
of the Laravel app
-
go into the container to build tables
Run this command to check if the app can connect to DB.
Recap
- docker volume (mapping local dir to container dir)
- how to manage containers
- container interact with container (172.17.0.1)
Command cheat sheet