Drop-in Docker-based development environment starter for PHP.
Yeah, just add this package in a sub-directory of your project, do some configurations, and you are good to start your project development up with Docker.
gitmakedockerdocker-compose
There are 2 ways to install A2Way Drop-in-Docker PHP in your project.
- As a Git submodule.
- Copy-n-paste into a directory.
If you choose "1", you can receive semi-automatic (You'll have to git pull manually.) updates from upstream (https://github.com/a2way-com/drop-in-docker-php), but you won't be able to commit any changes to it.
If you choose "2", you can make changes to it, and commit them as a part of your project, but you cannot get easy updates as in "1" choice. You can keep an eye for any updates, and manually apply them, or make this portion of the code a submodule repo you manage yourself, and pull changes from upstream to that repo.
git submodule add https://github.com/a2way-com/drop-in-docker-php.git
If you clone a repo with this added as a submodule, you will have to run the following command to complete pulling this and any other submodules.
git submodule initgit submodule update
Download this repo as a ZIP, extract it, copy it, and then paste it into your project. The drop-in-docker-php directory should be placed as a sub-directory of your project.
First, open your shell's "RC File" (Eg: ~/.bashrc and ~/.zshrc.), and add the following line to the end of it:
export UID=<Your Linux User ID.>- Make a copy of
tmp.envas.env. - Make copies of all the
tmp.*.envfiles in theenvdirectory. The resulting copies should have their original copies' names without the "tmp" part (Eg:tmp.adminer.envshould be copied asadminer.env.).
| Key | Description |
|---|---|
| ADMINER_PORT | Port to run Adminer on. |
| APP_IMAGE | Name to tag App Docker Image with. |
| APP_VOLUMES_SRC | Path to source code relative to drop-in-docker-php/docker-compose.yml. |
| MAILHOG_SMTP_PORT | Port for MailHog to listen for SMTP traffic. |
| MAILHOG_UI_PORT | Port for MailHog to expose UI. |
| MYSQL_PORT | Port for MySQL to listen to. |
| PROXY_IMAGE | Name to tag Proxy Docker Image with. |
| PROXY_PORT | Port for Proxy to listen to HTTP traffic. |
| STATIC_VOLUMES_PUBLIC | Path to public files directory relative to drop-in-docker-php/docker-compose.yml. |
| UID | Your Linux User ID. |
| Key | Description |
|---|---|
| ADMINER_DEFAULT_SERVER | Default server address. This should match the service name for MySQL in docker-compose.yml. |
You can put any app specific environment variable key value pairs here.
| Key | Description |
|---|---|
| MYSQL_ROOT_PASSWORD | Default password for root MySQL user. |
You can put any other environment variables for MySQL here too.
| Key | Description |
|---|---|
| PHP_FPM_HOST | PHP FPM server address. This should match the service name for App in in docker-compose.yml. |
| PUBLIC_PATH | Path to public files directory relative to drop-in-docker-php/docker-compose.yml. |
| STATIC_CONTENT_HOST | Static content server address. This should match the service name for Static in in docker-compose.yml. |
First, install and configure A2Way Drop-in-Docker PHP as described in above sections.
If your project's source directory is in the parent level of the drop-in-docker-php directory, set APP_VOLUMES_SRC variable's value to ../. If the source directory is in the sibling level, and the source directory's name is "src", set APP_VOLUMES_SRC's value to ../src/. Be sure to replace "src" with your own source directory's name. Basically, you have to put the path to the source directory relative to the docker-compose.yml file.
If your project use a sub-directory of your souce directory as the public directory, set its path relative to the docker-compose.yml file as the value of STATIC_VOLUMES_PUBLIC. Also, in env/proxy.env, set that sub directory's path relative to the source directory as the value of PUBLIC_PATH. Otherwise, if your public directory is the same as your source directory, set STATIC_VOLUMES_PUBLIC's value to the relative path to the source directory, and set PUBLIC_PATH to ./.
Then, go inside the drop-in-docker-php directory, and run make up to start your project in Docker.
| Command | Description |
|---|---|
| down | Stops the development environment. |
| shell | Logs in to the Docker Container for the App. |
| up | Starts the development environment. |
| up-f | Starts the development environment in foreground, so you can view logs from the containers. |
Add the following lines to Dockerfiles/app.Dockerfile, just under the RUN apk --update add shadow line:
RUN apk --update add php-session
RUN apk --update add php-tokenizer
RUN apk --update add php-xml
RUN apk --update add php-dom
RUN apk --update add php-xmlwriter
RUN apk --update add php-fileinfo
This is just a starter. You have to customize this to fit your project (Eg: Add more services to docker-compose.yml and add more commands to Dockerfiles.). You are expected to know how to work with Docker and Docker Compose to use this.
If you think your addition is common enough and it should be included by default, feel free to send a Pull Request to https://github.com/a2way-com/drop-in-docker-php.
Copyright (c) 2021. Supun Budhajeewa <budhajeewa.com>
If you like my work here, consider making a contribution :).
