Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

docker-starter

> DevOps
Open source

️ A skeleton to start a new web project with PHP, Docker and Castor

356 stars0 likes1 views
WebsiteGitHub

About

️ A skeleton to start a new web project with PHP, Docker and Castor

Docker Starter

A docker-based infrastructure wrapped in an easy-to-use command line, oriented for PHP projects.

This repository contains a collection of Dockerfile and docker-compose configurations for your PHP projects with built-in support for HTTPS, custom domain, databases, workers... and is used as a foundation for our projects at JoliCode.

[!WARNING] You are reading the README of version 4 that uses Castor.

  • If you are using Invoke, you can read the dedicated README;
  • If you are using Fabric, you can read the dedicated README;

Project configuration

Before executing any command, you need to configure a few parameters in the castor.php file, in the create_default_variables() function:

  • project_name (required): This will be used to prefix all docker objects (network, images, containers);

  • root_domain (optional, default: project_name + '.test'): This is the root domain where the application will be available;

  • extra_domains (optional): This contains extra domains where the application will be available;

  • php_version (optional, default: 8.5): This is the PHP version installed inside the containers.

For example:

php
function create_default_variables(): array
{
    $projectName = 'app';
    $tld = 'test';

    return [
        'project_name' => $projectName,
        'root_domain' => "{$projectName}.{$tld}",
        'extra_domains' => [
            "www.{$projectName}.{$tld}",
            "admin.{$projectName}.{$tld}",
            "api.{$projectName}.{$tld}",
        ],
        'php_version' => 8.5,
    ];
)

Will give you https://app.test, https://www.app.test, https://api.app.test and https://admin.app.test pointing at your application/ directory.

[!NOTE] Some castor tasks have been added for DX purposes. Checkout and adapt the tasks install, migrate and cache_clear to your project.

Git worktree support

When running castor commands inside a git worktree, the stack is automatically isolated from other worktrees:

  • Docker Compose project name, volumes, and networks are suffixed with -wt-
  • Ports are derived from the worktree name (use castor docker:ports to display them)

This allows running multiple feature branches in parallel without conflicts.

Usage documentation

We provide a README.dist.md to bootstrap your project documentation, with everything you need to know to start and interact with the infrastructure.

If you want to install a Symfony project, you can run (before castor init):

bash
castor symfony [--web-app]

To replace this README with the dist, and remove all unnecessary files, you can run:

bash
castor init

[!NOTE] This command can be run only once

Also, in order to improve your usage of castor scripts, you can install console autocompletion script.

If you are using bash:

bash
castor completion | sudo tee /etc/bash_completion.d/castor

If you are using something else, please refer to your shell documentation. You may need to use castor completion > /to/somewhere.

Castor supports completion for bash, zsh & fish shells.

Cookbooks

How to install third party tools with Composer

Read the cookbook

If you want to install some third party tools with Composer, it is recommended to install them in their dedicated directory. PHPStan and PHP-CS-Fixer are already installed in the tools directory.

We suggest to:

  1. create a composer.json which requires only this tool in tools//composer.json;

  2. create an executable symbolic link to the tool from the root directory of the project: ln -s ..//vendor/bin/ tools/bin/;

[!NOTE] Relative symlinks works here, because the first part of the command is relative to the second part, not to the current directory.

Since tools/bin path is appended to the $PATH, tools will be available globally in the builder container.

How to change the layout of the project

Read the cookbook

If you want to rename the application directory, or even move its content to the root directory, you have to edit each reference to it. Theses references represent each application entry point, whether it be over HTTP or CLI. Usually, there is three places where you need to do it:

  • In Nginx configuration file: infrastructure/docker/services/php/frontend/etc/nginx/nginx.conf. You need to update http.server.root option to the new path. For example:
    diff
    - root /var/www/application/public;
    + root /var/www/public;
  • In all workers configuration file: infrastructure/docker/docker-compose.worker.yml:
    diff
    - command: php -d memory_limit=1G /var/www/application/bin/console messenger:consume async --memory-limit=128M
    + command: php -d memory_limit=1G /var/www/bin/console messenger:consume async --memory-limit=128M
  • In the builder, to land in the right directory directly: infrastructure/docker/services/php/Dockerfile:
    diff
    - WORKDIR /var/www/application
    + WORKDIR /var/www

How to use MariaDB instead of PostgreSQL

Read the cookbook

In order to use MariaDB, you will need to apply this patch:

…

How to use MySQL instead of PostgreSQL

Read the cookbook

In order to use MySQL, you will need to follow the same steps as for MariaDB, but with the following configuration for the database service:

    mysql:
        image: mysql:8
        environment:
            - MYSQL_ALLOW_EMPTY_PASSWORD=1
        healthcheck:
            test: "mysqladmin ping -h localhost"
            interval: 5s
            timeout: 5s
            retries: 10
         volumes:
            - mysql-data:/var/lib/mysql

How to use with Webpack Encore

Read the cookbook

[!NOTE] this cookbook documents the integration of webpack 5+. For older version of webpack, use previous version of the docker starter.

If you want to use Webpack Encore in a Symfony project,

  1. Follow instructions on symfony.com to install webpack encore.

    You will need to follow these instructions too.

  2. Create a new service for encore:

    Add the following content to the docker-compose.yml file:

…

If the assets are not reachable, you may accept self-signed certificate. To do so, open a new tab at https://encore.app.test and click on accept.

How to use with AssetMapper

Read the cookbook

  1. Follow instructions on symfony.com to install AssetMapper.

  2. Remove this block in the infrastructure/docker/services/php/frontend/etc/nginx/nginx.conf file:

    location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg)$ {
        access_log off;
        add_header Cache-Control "no-cache";
    }
  3. Remove these lines in the infrastructure/docker/services/php/Dockerfile file:

…

How to add Elasticsearch and Kibana

Read the cookbook

In order to use Elasticsearch and Kibana, you should add the following content to the docker-compose.yml file:

…

Then, you will be able to browse:

  • https://kibana.
  • https://elasticsearch.

In your application, you can use the following configuration:

  • scheme: http;
  • host: elasticsearch;
  • port: 9200.

How to use with Sylius

Read the cookbook

If you want to install a Sylius project, you can run (before castor init):

bash
castor sylius

How to add RabbitMQ and its dashboard

Read the cookbook

In order to use RabbitMQ and its dashboard, you should add a new service:

dockerfile
# services/rabbitmq/Dockerfile
FROM rabbitmq:3-management-alpine

COPY etc/. /etc/

And you can add specific RabbitMQ configuration in the services/rabbitmq/etc/rabbitmq/rabbitmq.conf file:

# services/rabbitmq/etc/rabbitmq/rabbitmq.conf
vm_memory_high_watermark.absolute = 1GB

Finally, add the following content to the docker-compose.yml file:

…

In order to publish and consume messages with PHP, you need to install the php${PHP_VERSION}-amqp in the php image.

Then, you will be able to browse:

  • https://rabbitmq. (username: guest, password: guest)

In your application, you can use the following configuration:

  • host: rabbitmq;
  • username: guest;
  • password: guest;
  • port: rabbitmq.

For example in Symfony you can use: MESSENGER_TRANSPORT_DSN=amqp://guest:guest@rabbitmq:5672/%2f/messages.

How to add Redis and its dashboard

Read the cookbook

In order to use Redis and its dashboard, you should add the following content to the docker-compose.yml file:

…

In order to communicate with Redis, you need to install the php${PHP_VERSION}-redis in the php image.

Then, you will be able to browse:

  • https://redis.

In your application, you can use the following configuration:

  • host: redis;
  • port: 6379.

How to add Mailpit

Read the cookbook

In order to use Mailpit and its dashboard, you should add the following content to the docker-compose.yml file:

yaml
services:
    mail:
        image: axllent/mailpit
        environment:
            - MP_SMTP_BIND_ADDR=0.0.0.0:25
        labels:
            - "traefik.enable=true"
            - "project-name=${PROJECT_NAME}"
            - "traefik.http.routers.${PROJECT_NAME}-mail.rule=Host(`mail.${PROJECT_ROOT_DOMAIN}`)"
            - "traefik.http.routers.${PROJECT_NAME}-mail.tls=true"
            - "traefik.http.services.mail.loadbalancer.server.port=8025"
        profiles:
            - default

Then, you will be able to browse:

  • https://mail.

In your application, you can use the following configuration:

  • scheme: smtp;
  • host: mail;
  • port: 25.

For example in Symfony you can use: MAILER_DSN=smtp://mail:25.

How to add Mercure

Read the cookbook

In order to use Mercure, you should add the following content to the docker-compose.yml file:

yaml
services:
    mercure:
        image: dunglas/mercure
        environment:
            - "MERCURE_PUBLISHER_JWT_KEY=password"
            - "MERCURE_SUBSCRIBER_JWT_KEY=password"
            - "ALLOW_ANONYMOUS=1"
            - "CORS_ALLOWED_ORIGINS=*"
        labels:
            - "traefik.enable=true"
            - "project-name=${PROJECT_NAME}"
            - "traefik.http.routers.${PROJECT_NAME}-mercure.rule=Host(`mercure.${PROJECT_ROOT_DOMAIN}`)"
            - "traefik.http.routers.${PROJECT_NAME}-mercure.tls=true"
        profiles:
            - default

If you are using Symfony, you must put the following configuration in the .env file:

MERCURE_PUBLISH_URL=http://mercure/.well-known/mercure
MERCURE_JWT_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6W10sInB1Ymxpc2giOltdfX0.t9ZVMwTzmyjVs0u9s6MI7-oiXP-ywdihbAfPlghTBeQ

How to add redirection.io

Read the cookbook

In order to use redirection.io, you should add the following content to the docker-compose.yml file to run the agent:

yaml
services:
    redirectionio-agent:
        build: services/redirectionio-agent

Add the following file infrastructure/docker/services/redirectionio-agent/Dockerfile:

…

Add infrastructure/docker/services/redirectionio-agent/etc/redirectionio/agent.yml:

yaml
instance_name: "my-instance-dev" ### You may want to change this
listen: 0.0.0.0:10301

Then you'll need wget. In infrastructure/docker/services/php/Dockerfile, in stage frontend:

dockerfile
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        wget \
    && apt-get clean \

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPcastordockerdocker-composegithub-template

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理