feat: development support with docker

This commit is contained in:
Supan Adit Pratama 2022-05-02 17:14:58 +07:00
parent 5f36d147be
commit 730763a58a
4 changed files with 91 additions and 0 deletions

5
Caddyfile Normal file
View File

@ -0,0 +1,5 @@
:80 {
root * /srv/public
file_server
php_fastcgi todo:9000
}

10
PHP.Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM php:7.4-fpm
RUN apt-get update
RUN apt-get install -y git zip
RUN docker-php-ext-install pdo pdo_mysql
# Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

View File

@ -72,6 +72,56 @@ docker-compose exec todo-app php artisan migrate
docker-compose exec todo-app php artisan db:seed
```
## Development Using Docker
### Run Application
```bash
docker-compose -f docker-compose.dev.yml up -d
```
### Installing / Updating Dependencies
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv todo composer install # Composer Install
```
### Generate Key
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv todo php artisan key:generate # Generate Key
```
### Database Migration
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv todo php artisan migrate
```
### Database Seed
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv todo php artisan db:seed
```
### Shutdown Application
```bash
docker-compose -f docker-compose.dev.yml down
```
### Updating `.env`
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv todo php artisan config:cache
```
### Rebuilding Dockerfile
```bash
docker-compose -f docker-compose.dev.yml build
```
### Troubleshooting MySQL Won't Run In Docker
Run this script `sudo chown -R 1001:1001 mysql`

26
docker-compose.dev.yml Normal file
View File

@ -0,0 +1,26 @@
version: "3.8"
services:
todo:
build:
context: .
dockerfile: PHP.Dockerfile
volumes:
- "./:/srv"
caddy:
image: caddy:2.5.0-alpine
ports:
- "80:80"
volumes:
- "./Caddyfile:/etc/caddy/Caddyfile"
- "./:/srv"
mysqldb:
image: "bitnami/mysql:8.0"
ports:
- "3306:3306"
volumes:
- "./mysql:/bitnami/mysql/data"
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=todo