From 730763a58a1d80b724a393650d52eef7d7eab6e9 Mon Sep 17 00:00:00 2001 From: Supan Adit Pratama Date: Mon, 2 May 2022 17:14:58 +0700 Subject: [PATCH] feat: development support with docker --- Caddyfile | 5 +++++ PHP.Dockerfile | 10 +++++++++ README.md | 50 ++++++++++++++++++++++++++++++++++++++++++ docker-compose.dev.yml | 26 ++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 Caddyfile create mode 100644 PHP.Dockerfile create mode 100644 docker-compose.dev.yml diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..5e46be8 --- /dev/null +++ b/Caddyfile @@ -0,0 +1,5 @@ +:80 { + root * /srv/public + file_server + php_fastcgi todo:9000 +} diff --git a/PHP.Dockerfile b/PHP.Dockerfile new file mode 100644 index 0000000..664efd4 --- /dev/null +++ b/PHP.Dockerfile @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 3a54511..aa438f5 100755 --- a/README.md +++ b/README.md @@ -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` diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..7c29215 --- /dev/null +++ b/docker-compose.dev.yml @@ -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 \ No newline at end of file