larevio / docker-php-api
Docker api wrapper for laravel
1.0.0
2025-01-08 22:04 UTC
Requires
- ext-curl: *
- guzzlehttp/guzzle: >7
This package is auto-updated.
Last update: 2025-08-08 23:26:58 UTC
README
Docker API is a php wrapper compatible with docker engine api latest version (1.43).
This package was developed for my personal projects, and it is still on experimental phase.
The methods presented in this package are extremely limited, feel free to make pull requests.
Installation
PHP 8.0+ is required for this package
This package is available on packagist, install it with composer:
composer require larevio/docker-api
Usage
Create Docker instance
by docker http api
$docker = new \Larevio\DockerApi\Docker("http://localhost:2375", [], false);
or by unix socket
$docker = new \Larevio\DockerApi\Docker("/var/run/docker.sock", [], false)
Basic example
<?php require_once "vendor/autoload.php"; $docker = new \Larevio\DockerApi\Docker("http://localhost:2375", [], false); $testContainer = $docker->createContainer("TestContainer", "helloworld"); $testContainer->start(); $alreadyExistContainer = $docker->container("XXX"); $customNetwork = $docker->createNetwork("test"); $alreadyExistContainer->connectToNetwork($customNetwork); $alreadyExistContainer->setMemoryLimit(50000);
Laravel usage
This package is usable by laravel (8+)
Config
php artisan vendor:publish --provider="Larevio\DockerApi\DockerApiServiceProvider" --tag="config"
<?php return [ 'url' => "http://localhost:2222", // Custom guzzlehttp options (headers, timeout, etc.) // read more on https://docs.guzzlephp.org/en/stable/request-options.html 'options' => [ 'auth' => ["test", "test"] ], 'async' => true // Should all requests be async ? ];
Helpers
In laravel you will have global docker instance available through helpers.
docker()->info(); docker()->createContainer($name, $image); container($id); volume($id); network($id);