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_HOST: tcp address for the docker daemon (i.e. tcp://127.0.0.1:2376)
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)
DOCKER_HOST environment variable is not set, it will use
unix:///var/run/docker.sock as the default tcp address.
<?php use Docker\Docker; $docker = Docker::create();
You can connect to an arbitrary server by passing an instance of
<?php use Docker\Docker; use Docker\DockerClientFactory; $client = DockerClientFactory::create([ 'remote_socket' => 'tcp://127.0.0.1:2375', 'ssl' => false, ]); $docker = Docker::create($client);
DockerClientFactory will create a
Http\Client\Socket\Client, you can go on the
official documentation of the socket client
to learn about possible options.
Docker\Docker accepts any client from Httplug (respecting the
<?php 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: