> ## Documentation Index
> Fetch the complete documentation index at: https://docker-php.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# API versions

> Choose a Docker Engine API version and how requests negotiate with the daemon.

## Choose an API version

Docker PHP 4.1 works with Docker Engine API v1.45 to v1.57. Each version has its
own `docker-php/docker-php-api` release line with generated endpoints and
models. Without a direct API requirement, Composer installs the newest line.

To use a specific version, require its line next to the client:

```bash theme={null}
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. Docker renames models and changes fields between API versions;
for example, API 1.48 replaced `ContainersIdJsonGetResponse200` with
`ContainerInspectResponse`, and API 1.52 removed `getError()` from build, pull and
push progress frames. Check Docker's
[API version history](https://docs.docker.com/reference/api/engine/version-history/)
and the [Docker Engine API reference](https://docs.docker.com/reference/api/engine/)
for the version you use.

## Package versions

`docker-php/docker-php` follows semantic versioning.

`docker-php/docker-php-api` uses a four-part scheme:
`Jane-major.Docker-major.Docker-minor.revision`. For example, `7.1.57.0` means
Docker Engine API v1.57, generated with Jane 7, revision 0. Keep a direct API
requirement within one line, as above. A constraint such as `^7.1.45.0` allows
every newer Docker specification.

## Request URL version

The bundled factory negotiates the version in request URLs. Before the first
request it sends an unversioned `/_ping` and reads the daemon's maximum API
version from the response. Requests then use the lower of that version and the
installed API line, as the Docker CLI does. An older daemon keeps working with a
newer API package, and requests never ask for a version the installed models do
not describe. `DockerClientFactory::defaultApiVersion()` returns the installed
line's version.

To skip negotiation, set the version yourself. `DOCKER_API_VERSION` sets it from
the environment:

```bash theme={null}
DOCKER_API_VERSION=1.51 php your-script.php
```

The factory's `api_version` option sets it in PHP and overrides the environment:

```php theme={null}
<?php

use Docker\Docker;
use Docker\DockerClientFactory;

$httpClient = DockerClientFactory::create([
    'remote_socket' => 'unix:///var/run/docker.sock',
    'api_version' => '1.51',
]);
$docker = Docker::create($httpClient, [], [], false);
```

Both `1.51` and `v1.51` are accepted. The fourth argument disables the generated
server plugins because the factory already adds the API path.

A client you build yourself, such as [Guzzle](https://docker-php.mintlify.site/guides/guzzle.md), does not negotiate.
The generated server plugins prefix requests with the installed line's version,
so install a line your daemon supports.

> [!WARNING]
>
> Changing the URL version does not regenerate models or add newer fields and
> endpoints. With an older daemon, fields added after its API version are absent
> from responses and ignored in requests.

## Generated code

Each line is generated from Docker's specification for that version with Jane
7.14.4, without local patches. The API repository has one branch per line,
such as [`7.1.57`](https://github.com/docker-php/docker-php-api/tree/7.1.57); see its
[generation instructions](https://github.com/docker-php/docker-php-api#generation).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.