mandrasch / dokku-docker-php-db-demo

🚧 Simple PHP Example of Docker Image Deployment with Dokku - Work in Progress 🚧

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dokku-docker-php-db-demo

Simple PHP example of Docker Image Deployment with Dokku, it's my first try. Tried to keep it simple and lightweight.

⚠️ Beware: This is a demo project, please use with caution and double-check security. ⚠️

Fork of https://github.com/bkuhl/fpm-nginx.

The Docker Image is built via GitHub Action and pushed to GitHubs package registry. The Dokku instance pulls the image from there (after being informed by a GitHub Action trigger).


⚠️ It is currently not possible to deploy a docker compose build with different services, but you can build your webserver as image and deploy it to Dokku (dokku/dokku#5102). See https://dokkupose.netlify.app/ as well. ⚠️
Container Size
webserver

This is not intended for local development, for local development i use DDEV.

Build image locally

# run
docker-compose build

# build and run
docker-compose up --build

# with more output
BUILDKIT_PROGRESS=plain docker-compose up --build

You can ssh/jump into containers with Orbstack (Volumes > ... > Webserver > Open terminal) or Docker Desktop.

The generated image will be in a special folder like /Users/max/OrbStack/docker/images/, depends on your Docker runtime.

TODOs

How was this created?

ddev config --project-type=php --database="mysql:8.0"
ddev start

ddev composer init 
ddev composer require vlucas/phpdotenv

ddev npm init -y
ddev npm i vite
# Added vite.config.js
# Added scripts in package.json

# Added docker-compose.yml and Dockerfiles

Login to Dokku server:

dokku apps:create dokku-docker-php-db-demo

# https://dokku.com/docs/deployment/methods/image#initializing-an-app-repository-from-a-docker-image
dokku git:from-image dokku-docker-php-db-demo ghcr.io/mandrasch/dokku-docker-php-db-demo:latest

# After successful deployments, latest won't repull?
# (If the image tag doesn't change, that won't trigger a rebuild (as documented),
# see: https://github.com/dokku/dokku/issues/6302 - # or use :<sha> for pull?
docker pull ghcr.io/mandrasch/dokku-docker-php-db-demo
dokku ps:rebuild dokku-docker-php-db-demo

Why?

Why did I try this approach with a Docker Image + building it in GitHub actions?

The advantage of using Dockerfile is that you can add exactly the steps you need, and is also portable: if I want to move from Dokku to some other provider, whether PAAS or, say, a Kubernetes pod, you can re-use your Dockerfile. As each step or layer is cached it also makes for a fast build.

Source: https://danjacob.net/posts/single-docker-file/

There's a couple ways to deploy your app to dokku. The most common workflow being the heroku style git push. This approach is convenient, but means app builds take place on your server. This is perhaps not a problem for most people, but was quite a big problem for me as I'm deploying apps with complicated builds (using webpack) that take long time to complete and require a lot of machine resources (like a LOT of RAM and a decent amount of processing power). These builds ultimately kill my runtime server and my running apps are unresponsive while a build is taking place.

Source: https://richardwillis.info/blog/deploy-dokku-app-remote-docker-image

Acknowledgements

Thanks to

About

🚧 Simple PHP Example of Docker Image Deployment with Dokku - Work in Progress 🚧


Languages

Language:Dockerfile 73.4%Language:PHP 12.9%Language:Shell 8.7%Language:JavaScript 4.9%