This is my development docker build for multiple projects.
- php 7.4
- php 7.4 xdebug (this container extends from the first one)
- mariadb:latest
- redis:alpine
- mailhog (localhost:8025)
- nginx:alpine
- All of the above
- Elasticsearch v7.8
- Kibana v7.8 (localhost:5601)
- RabbitMq v3.8.5 management (localhost:15672)
- Jenkins alpine (localhost:8081)
- redis-commander:latest (localhost:8082)
- Nginx will only use the php xdebug container if
XDEBUG_SESSION
cookie is active. Otherwise, the normal php container without xdebug installed will be used. This increased my development speed. Use an empty value for the cookie. - If you are a mac user, there is a script to execute to mount the data volume as NFS volume for performance reasons.
- Use this docker setup for multiple projects at once.
- I used only official base images. If you want to change sth. Do it.
- Https only with a selfsigned certificate in nginx container.
- Composer and nodejs v14.5 in php containers available.
- Every outgoing mail with mail() sent from php containers will be displayed by mailhog under localhost:8025. Mails will not leave your local development environment anymore ;-)
- Use Jenkins for cronjob management. Jenkins will connect to the php container via ssh plugin and can executes commands.
- There are common environment variables by default which will be passed to php containers. Here is a list of them and there default values:
DB_HOST: "localhost"
DB_PORT: "3306"
DB_USER: "${DEFAULT_USER}"
DB_PASSWORD: "${DEFAULT_PASSWORD}"
REDIS_HOST: "redis"
REDIS_PORT: "6379"
REDIS_PASSWORD: "${DEFAULT_PASSWORD}"
ELASTICSEARCH_HOST: "elasticsearch"
ELASTICSEARCH_PORT: "9200"
RABBITMQ_HOST: "rabbitmq"
RABBITMQ_PORT: "5672"
Decide yourself which docker-compose file you would like to use or just delete the services you do not need.
Change them as you like. The credentials will be used as user/password for every service.
COMPOSE_PROJECT_NAME=pws
WORKSPACE_PATH=/my/path/to/workspace
DEFAULT_USER=dev
DEFAULT_PASSWORD=secret
It is recommended that you don´t change the project name. Volumes will become this prefix. If you change it, some details in this guide will be wrong.
- Docker
- There is a required naming and directory structure for your projects.
- Usage of TLD ".test" for your local development domain is required.
- your project root directories has the same name as your domain. For example:
"my-project.test"
- Nginx points automatically to a "public" directory in your project root.
- Add phing.xml as phing file
- Execute target docker:init:dev
- Folder Structure / Naming
Pull this repository and put it at the same level as your project root dirs.
-- workspace
---- docker-setup
---- your-first-project.test
---- your-second-project.test
---- your-third-project.test
-
Environment file
Copy the file.env.dist
to.env
at the same level. -
Enviroment variables
Replace the string "%%PATH_TO_WORKSPACE%%" in your.env
file with the absolute path to your workspace directory.
example value: "/my/path/to/workspace"
Set the credentials as you like. They will be used for every service.
For example mariadb
kibana
redis
etc...
- Hosts file
Use the Windows/Unix/Mac hosts file to add local development domains for your projects. This is an example:
127.0.0.1 your-fist-project.test
127.0.0.1 your-second-project.test
127.0.0.1 your-third-project.test
Remember that this domain name is also your directory name of your project.
- Build
Execute the commands and wait for the build.
cd /path/to/workspace/docker-setup
docker-compose up -d
- Docker for Mac
Docker for mac users has a slow file sync by default. After the installation! You can execute following commands to get more performance. It will mount your data workspace volume as nfs.
docker-compose stop
docker-compose volume rm pws_pws-volume-data
./scripts/nfs_for_native_docker.sh
- From time to time you will add more projects.
For examplesuper-project.test
- Add this line to your hosts file
127.0.0.1 super-project.test
- Create a project directory
/path/to/workspace/super-project.test
- Create a public directory
/path/to/workspace/super-project.test/public
- Create your index.php file
/path/to/workspace/super-project.test/public/index.php
- Start coding.
If you don´t like to have one docker stack for all of your projects, you can create a custom docker build for each based on this repository. You don´t have to change much.
Have fun!
The idea of multiple php containers comes from here:
https://jtreminio.com/blog/developing-at-full-speed-with-xdebug/
The script ./scripts/nfs_for_native_docker.sh
for the nfs mount is from here:
https://medium.com/@sean.handley/how-to-set-up-docker-for-mac-with-native-nfs-145151458adc