PHPackages                             axy/docker-dockerfile-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. axy/docker-dockerfile-builder

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

axy/docker-dockerfile-builder
=============================

Builds a dockerfile

0.0.1(5y ago)016MITPHPPHP &gt;=8.0

Since May 14Pushed 5y ago1 watchersCompare

[ Source](https://github.com/axypro/docker-dockerfile-builder)[ Packagist](https://packagist.org/packages/axy/docker-dockerfile-builder)[ Docs](https://github.com/axypro/docker-dockerfile-builder)[ RSS](/packages/axy-docker-dockerfile-builder/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

axy\\docker\\dockerfile\\builder
================================

[](#axydockerdockerfilebuilder)

[![Latest Stable Version](https://camo.githubusercontent.com/ae31ef481525e450b575d7221cd35d001ad21823ba86f28239dd8a8ce846ef5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6178792f646f636b65722d646f636b657266696c652d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/axy/docker-dockerfile-builder)[![Minimum PHP Version](https://camo.githubusercontent.com/7f91fd16f805b376c8b9137ddc479aabdc9f79d19807832f85606cb3b74409c4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e302d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![License](https://camo.githubusercontent.com/6aea11418eec7a70d14712ec6af053110c22176ce67d4e81149c0238355b602a/68747470733a2f2f706f7365722e707567782e6f72672f6178792f646f636b65722d646f636b657266696c652d6275696c6465722f6c6963656e7365)](LICENSE)

The class that builds dockerfile.

The package is used for specific things. Some options are not tested. Some things are done ineffectively. Using this package is recommended for nobody.

Hierarchy of classes
--------------------

[](#hierarchy-of-classes)

- `DockerfileBuileder` - common builder
    - `DockerfilePHPBuilder` - added some PHP specific features

Example
-------

[](#example)

```
use axy\docker\dockerfile\builder\DockerfilePHPBuilder;

$builder = new DockerfilePHPBuilder('8.0', 'fpm', false);

$builder->labels['author'] = 'Me';
$builder->env['var'] = 'value';
$builder->user = '1000:1000';
$builder->cmd = 'php -m';

$builder->workdir('/var/www/app');
$builder->copy('file.php', 'index.php', '1000:1000');
$builder->packages(['curl', 'libpng-dev', 'libonig-dev', 'zip'], 'Install CURL etc');
$builder->extensions = ['bcmath', 'mbstring', 'pdo_mysql'];
$builder->pecl = ['xdebug'];
$builder->ini['error_reporting'] = 'E_ALL';
$builder->ini['post_max_size'] = '128M';

echo $builder->build();
```

Result:

```
FROM php:8.0-fpm

LABEL author="Me"

ENV var=value

WORKDIR /var/www/app

COPY --chown=1000:1000 file.php index.php

# Install CURL etc
RUN apt-get update && apt-get install -y \
    curl \
    libpng-dev \
    libonig-dev \
    zip

RUN docker-php-ext-install \
    bcmath \
    mbstring \
    pdo_mysql \
&& pecl install \
    xdebug \
&& docker-php-ext-enable \
    xdebug \
&& echo "error_reporting=E_ALL" >> /usr/local/etc/php/conf.d/docker.ini \
&& echo "post_max_size=128M" >> /usr/local/etc/php/conf.d/docker.ini \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN rm -rf /var/lib/apt/lists/*

CMD php -m

USER 1000:1000

```

DockerfileBuilder
-----------------

[](#dockerfilebuilder)

- `__construct(public string $image, public bool $isAlpine = true)`
    - `image` - the image name
    - `isAlpine` - use alpine distributive (see "Package Manager" below)

### Properties

[](#properties)

- `string|array|null $cmd` - CMD instruction (NULL - no CMD)
- `string|array|null $entrypoint` - see CMD
- `string[] $labels` - LABELs (key =&gt; value)
- `string[] $env` - environment variables (key =&gt; value)
- `string[] $directives` - directives (key =&gt; value)
- `string[] $args` - ARGs (key =&gt; value)
- `?string $syntax` - `syntax` directive separately
- `?string $escape` - `escape` directive separately
- `string[] $volume` - list of volumes
- `string[] $expose` - list of expose ports
- `bool $isPackagesCacheDisabled` - see "Package Manager" below

### Methods

[](#methods)

All these methods add one instruction to the dockerfile. The argument `$comment` add comment line before the instruction.

- `instruction(string|string[] $instruction, ?string $comment)`
    - `$instruction` - an instruction as string or multiline (joined by "")
- `run(string|string[] $commands, ?string $comment)`
    - `$commands` - a command for `RUN` instructions or a list of commands (joined by "&amp;&amp;")
- `copy(string|string[] $src, string $dest, ?string $chown)` - COPY instruction
- `add(string|string[] $src, string $dest, ?string $chown)` - ADD instruction
- `workdir(string $dir, ?string $comment = null)` - WORKDIR instruction
- `packages(string[] $packages, ?string $comment)`
    - `$packages` - a list of packages for installation
    - See "Package Manager" below

### Build

[](#build)

- `build(bool $pretty = true)` - returns the dockerfile content
    - `$pretty` - if FALSE, empty lines and comments will be deleted

### Package Manager

[](#package-manager)

- Alpine uses "apk"
- Not alpine uses "apt-get"
- Before install "update" will be performed
- With multiple call `packages()`, "update" will be performed only for the first
- If `$isPackagesCacheDisabled` is TRUE (by default)
    - alpine - install will be executed with `--no-cache`
    - other - the cache directory will be deleted at the end

DockerfilePHPBuilder
--------------------

[](#dockerfilephpbuilder)

- `bool $isComposerRequired` - if TRUE (by default) the composer will be installed globally
- `string[] $extensions` - the list of names of extensions that required for installation
- `string[] $pecl` - the list of names of extensions that installed via pecl
- `string[] $ini` - the list of php.ini settings (key =&gt; value)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1831d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e5b3a2db8d5614167d4510019e3373dbba63c6aade58d38d23f3e7d2e63c3c4a?d=identicon)[axy](/maintainers/axy)

---

Top Contributors

[![vasa-c](https://avatars.githubusercontent.com/u/557081?v=4)](https://github.com/vasa-c "vasa-c (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/axy-docker-dockerfile-builder/health.svg)

```
[![Health](https://phpackages.com/badges/axy-docker-dockerfile-builder/health.svg)](https://phpackages.com/packages/axy-docker-dockerfile-builder)
```

###  Alternatives

[deployer/deployer

Deployment Tool

11.1k25.4M207](/packages/deployer-deployer)[appwrite/server-ce

End to end backend server for frontend and mobile apps.

55.3k84.2k](/packages/appwrite-server-ce)[pragmarx/health

Laravel Server &amp; App Health Monitor and Notifier

2.0k1.0M2](/packages/pragmarx-health)[felixfbecker/language-server-protocol

PHP classes for the Language Server Protocol

22476.7M6](/packages/felixfbecker-language-server-protocol)[heroku/heroku-buildpack-php

Toolkit for starting a PHP application locally, with or without foreman, using the same config for PHP and Apache2/Nginx as on Heroku

8161.3M10](/packages/heroku-heroku-buildpack-php)[tiamo/phpas2

PHPAS2 is a php-based implementation of the EDIINT AS2 standard

4674.7k](/packages/tiamo-phpas2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
