定制 larevio/docker-php-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

larevio/docker-php-api

最新稳定版本:1.0.0

Composer 安装命令:

composer require larevio/docker-php-api

包简介

Docker api wrapper for laravel

README 文档

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);

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-08