This repo contains the docker compose configuration to set up various Docker containers for PHP development.
This package was developed for my own personal use. It might not suit your needs or be documented properly, and may change at any time.
NOTE: This package was written for use in Ubuntu, and has not been tested on a Mac.
Macs have an older version of bash that will stop the ./doc
shell script from working (associative arrays were first introduced in bash 4).
Mac users may need to turn the .env
SET_WWW_DATA_USER
option off.
- Clone the repository:
git clone https://github.com/code-distortion/php-docker-dev.git .
- Create a
.env
file by making a copy of.env.example
, and update it with the settings you need. - Build the containers using the
./doc
docker compose wrapper:./doc up -d --build
The ./doc
bash script is a docker compose wrapper.
It chooses which compose/xxx.yml files to use, as well as provide shortcuts for common docker compose commands.
Use this to interact with the containers instead of using docker compose directly.
./doc
first looks for the available compose/*.yml
files. Each file represents one container:
mailpit.yml
mariadb.yml
mysql.yml
mysql-memory.yml
nginx.yml
node.yml
ollama.yml
php.yml
postgres.yml
redis.yml
selenium-chrome.yml
It then checks with .env
to see which ones are enabled - via corresponding xxx_CONTAINER=true
values:
MAILPIT_CONTAINER=false
MARIADB_CONTAINER=false
MYSQL_CONTAINER=false
MYSQL_MEMORY_CONTAINER=false
NGINX_CONTAINER=false
NODE_CONTAINER=false
OLLAMA_CONTAINER=false
PHP_CONTAINER=true
PHP_OLD_CONTAINER=false
POSTGRES_CONTAINER=false
PYTHON_CONTAINER=false
REDIS_CONTAINER=false
SELENIUM_CHROME_CONTAINER=false
Extra containers can be added by adding a
compose/xxx.yml
file and a correspondingxxx_CONTAINER=true
value to the.env
file. They will be picked up automatically when using./doc
.
It then passes execution to docker compose, passing the enabled .yml configuration files:
# this command
./doc ps
# will run
docker compose --project-directory=. -f compose/php.yml ps
# (if the PHP container is the one that's enabled)
- All regular docker compose commands are passed through to docker compose. e.g.
- Build the containers:
./doc up -d --build
- Stop containers:
./doc stop
- Show container status:
./doc ps
- etc.
- Build the containers:
- Bash into a container by passing the container name. e.g.
./doc php
./doc mysql
- Bash into a container as root by passing the container name. e.g.
./doc sudo php
- Enter into the database mysql client (only when the MySQL container is being used).
./doc db
- Run a command in a container. e.g.
./doc php whoami
- Run a command in a container as root. e.g.
./doc sudo php whoami
You can change the image used for any container by updating your .env
file.
Choose the PHP version and pick other settings in the .env
file.
You have the option of setting the www-data user's uid and gid in the PHP container.
./doc
picks the current host user's uid and gid by default, although you can hard-code them via WWW_DATA_UID
and WWW_DATA_GID
in the .env
file.
This allows for the www-data user in the container to have the same access to files as your host user.
This is applied at build-time, and is enabled by default. You can turn it off by setting SET_WWW_DATA_USER=false
in the .env
file.
When inside the PHP container, you can open the MySQL client and connect straight to the database by running db
(only when the MySQL container is being used).
Uses the axllent/mailpit:latest
image.
Uses the mariadb:11.6.2
image.
Uses the mysql:8.4
image.
Uses the mysql:8.4
image.
Runs the container with the /var/lib/mysql
as a tmpfs volume, which means the data is stored in memory and is lost when the container is stopped. Which is useful for running tests.
Uses the nginx:1-alpine-slim
image.
Uses the node:23-bookworm
image.
Uses the ollama/ollama:latest
image.
Uses the php:8.4.1-fpm-bookworm
image.
Uses the postgres:17-alpine
image.
Uses the python:latest
image.
Uses the redis:alpine
image.
Uses the selenium/standalone-chrome:latest
image.
The MIT License (MIT). Please see License File for more information.