Connecting to Docker

Default, with environment variables

By default, Docker-PHP uses the the same environment variables as the Docker command line to connect to a running docker daemon:

  • DOCKER_HOST: tcp address for the docker daemon (i.e. tcp://
  • DOCKER_TLS_VERIFY: if set to true use tls for authentication of the client
  • DOCKER_CERT_PATH: path for the client certificates to use for authentication
  • DOCKER_PEER_NAME: peer name of the docker daemon (as set in the certificate)

If the DOCKER_HOST environment variable is not set, it will use unix:///var/run/docker.sock as the default tcp address.


use Docker\Docker;

$docker = Docker::create();

Custom connection

You can connect to an arbitrary server by passing an instance of Docker\DockerClient to Docker\Docker :


use Docker\Docker;
use Docker\DockerClientFactory;

$client = DockerClientFactory::create([
    'remote_socket' => 'tcp://',
    'ssl' => false,
$docker = Docker::create($client);

Since DockerClientFactory will create a Http\Client\Socket\Client, you can go on the official documentation of the socket client to learn about possible options.

Custom client

In fact Docker\Docker accepts any client from Httplug (respecting the Http\Client\HttpClient interface).

So you can use React, Guzzle or any other adapters / clients.


use Docker\Docker;
use GuzzleHttp\Client as GuzzleClient;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;

$config = [
    // Config params
$guzzle = new GuzzleClient($config);
$adapter = new GuzzleAdapter($guzzle);
$docker = Docker::create($adapter);

However not all clients fully support Docker daemon features, such as unix socket domain connection, real time streaming, ... That's why it's strongly encouraged to use the Socket Http Client which supports all the docker daemon features.

Also this client needs to be decorated by a plugin system. At least 2 plugins are required: