stage1 / docker-php
A Docker PHP client
Fund package maintenance!
Requires
- php: >=8.1
- docker-php/docker-php-api: >=7.1.45.0 <7.1.57.0
- nyholm/psr7: ^1.8
- php-http/client-common: ^2.7
- php-http/discovery: ^1.19
- php-http/socket-client: ^2.3
- psr/http-message: ^2.0
- symfony/filesystem: ^6.3 || ^7.0 || ^8.0
- symfony/process: ^6.3 || ^7.0 || ^8.0
- symfony/serializer: ^6.3 || ^7.0 || ^8.0
Requires (Dev)
- ext-curl: *
- ergebnis/composer-normalize: ^2.42
- friendsofphp/php-cs-fixer: ^3.8
- guzzlehttp/guzzle: ^7.9 || ^8.0
- php-parallel-lint/php-parallel-lint: ^1.2
- phpstan/phpstan: ^1.10 || ^2.0
- phpunit/phpunit: ^10.5.46
- psy/psysh: ^0.12.8
- roave/security-advisories: dev-latest
Suggests
None
Provides
None
Conflicts
- beluga-php/docker-php: *
- jane-php/json-schema-runtime: <7.14.4
- jane-php/open-api-runtime: <7.14.4
- nikic/php-parser: <4.13
- php-http/message: <1.16
Replaces
None
- dev-main / 4.0.x-dev
- v4.0.1
- v4.0.0
- 3.x-dev
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.0
- dev-master / 2.x-dev
- v2.0.0
- 1.24.x-dev
- 1.24.0
- 1.23.x-dev
- 1.23.2
- 1.23.1
- 1.23.0
- 1.22.x-dev
- 1.22.3
- 1.22.2
- 1.22.1
- 1.22.0
- 1.21.x-dev
- 1.21.4
- 1.21.3
- 1.21.2
- 1.21.1
- 1.21.0
- v0.5.0
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.0
- dev-feature/interactive-exec
This package is auto-updated.
Last update: 2026-10-09 07:54:34 UTC
README
Docker PHP (for lack of a better name) is a Docker client written in PHP. This library aims to reach 100% API support of the Docker Engine.
Documentation
The version 4.x documentation is available. Its source lives in docs/; see DOCUMENTATION.md to preview and edit it locally. The legacy documentation remains available for earlier releases.
New maintainers
After this repository was archived in 2019, the code was forked in beluga-php/docker-php, where maintenance and improvements continued.
We later contacted joelwurtz and agreed to take over
maintenance of the original docker-php/docker-php repository to give you a
better upgrade path. Development will continue here, and we will archive
beluga-php/docker-php once the migration is complete.
Version 4.0 works with Docker Engine API v1.45 to v1.56. See Upgrading to 4.0 below for how to migrate from existing releases.
Requirements
- PHP 8.1 or later, with the
mbstringextension. - Composer.
- Access to a Docker daemon with API v1.45 or later (Docker Engine 26.0 or later).
Installation
composer require "docker-php/docker-php:^4.0"
Composer also installs docker-php/docker-php-api, choosing the newest API line
unless you require one. See Docker API versions.
Usage
<?php require __DIR__ . '/vendor/autoload.php'; use Docker\Docker; $docker = Docker::create(); foreach ($docker->containerList(['all' => true]) as $container) { printf("%s\t%s\n", $container->getId(), $container->getImage()); }
Endpoint methods return generated models where the API defines a response body. Their PHPDoc lists accepted parameters, return types and API exceptions.
Docker::create() connects through unix:///var/run/docker.sock by default.
Environment variables are optional. See connection settings
and the Guzzle examples for
custom sockets, remote daemons and TLS configuration.
For streaming output, see container logs, command output and the streaming reference. These guides cover callback streams, TTY output and raw response framing.
Docker API versions
Each Docker Engine API version has its own docker-php/docker-php-api line with
generated endpoints and models. The line uses the four-part version
Jane-major.Docker-major.Docker-minor.revision: 7.1.56.0 means Docker API 1.56,
generated with Jane 7, revision 0. To use a specific version, require its line:
composer require "docker-php/docker-php:^4.0" "docker-php/docker-php-api:>=7.1.51.0 <7.1.52.0"
Pin a line if your code names generated models or calls methods that differ between versions. See the official Docker Engine API reference for each version's endpoints, parameters and response schemas.
The bundled connection factory negotiates the version in request URLs: it uses
the lower of the installed line and the daemon's maximum API version, as the
Docker CLI does. DOCKER_API_VERSION or the factory's api_version option fix
the version instead. Changing the URL version does not change the generated
models. See API versions.
Upgrading to 4.0
Most applications come from the original docker-php 2.x client or from
beluga-php/docker-php 1.45.x. Follow the section for your current package,
then check the 3.x changes, because 4.0 also changes
defaults that 2.x and Beluga applications rely on.
From docker-php 2.x
Version 4.0 requires PHP 8.1 or later, PSR-7 v2 and Jane 7-generated models. Review endpoint signatures, model types and HTTP client dependencies before upgrading. Check log and exec consumers against the streaming documentation.
Change the client requirement to docker-php/docker-php:^4.0. Remove an explicit
docker-php/docker-php-api:4.1.* requirement, or change it to one API line as
shown above. Update dependencies, test your application and commit its updated
composer.lock.
From beluga-php
Version 4.0 continues the client maintained under beluga-php/docker-php.
The PHP namespaces remain Docker and Docker\API.
Remove the beluga-php/docker-php requirement and any explicit
beluga-php/docker-php-api requirement from composer.json. Add
docker-php/docker-php:^4.0; to keep the Beluga v1.45 models, also require
docker-php/docker-php-api:>=7.1.45.0 <7.1.46.0. Resolve the package changes
together, then test the application and commit its updated composer.lock.
Install one package family at a time: the Beluga and original packages contain the same PHP classes.
From docker-php 3.x
- Composer now installs the newest API line unless you require one. Require
docker-php/docker-php-api:>=7.1.45.0 <7.1.46.0to keep the 3.x models. - Requests negotiate the API version with the daemon unless you set one.
- Error statuses the generated endpoints do not handle throw an
UnexpectedStatusCodeException. CallthrowOnUnexpectedStatus(false)to returnnullinstead. Contextapplies.dockerignore. CallapplyDockerignore(false)to archive the whole directory.
Applications that cannot upgrade yet can stay on ^3.3. See the
upgrade guide for model
changes between API versions.
Development
Install dependencies and pull the image used by the integration tests:
composer install docker pull busybox:latest
Run the test suite and static analysis:
composer run-script test-ci composer run-script phpstan
The integration tests create Docker resources on the configured daemon. Use a development daemon when running them. See CONTRIBUTING.md for contribution instructions.
Credits
Docker PHP was created by Geoffrey Bachelet and Joel Wurtz. Development continued under beluga-php before the return to the original repositories.
License
MIT.