ibra-akv/php-docker-client

PHP的Docker API驱动程序。

3.41.3 2022-09-27 17:54 UTC

This package is auto-updated.

Last update: 2024-09-27 23:00:00 UTC


README

CircleCI Coverage Status

PHP的Docker API驱动程序。

Docker配置

为了能够连接,必须将Docker Engine API暴露在本地端口上。

1. 编辑默认位于/lib/systemd/system/docker.servicedocker.service(在debian中)

从以下内容

# /lib/systemd/system/docker.service
...
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
...

到以下内容

# /lib/systemd/system/docker.service
...
ExecStart=/usr/bin/dockerd
...
2. 编辑/etc/docker/daemon.json以在127.0.0.1:2375处暴露Docker API

在json文件中添加以下内容到hosts

{
  ...
  "hosts": ["fd://", "tcp://127.0.0.1:2375"]
  ...
}
3. 完全重启Docker
systemctl daemon-reload
systemctl restart docker
service docker restart

安装

composer require ibra-akv/php-docker-client

用法

初始化客户端

use IterativeCode\Component\DockerClient\DockerClient;

$docker = new DockerClient([
    'local_endpoint' => 'https://:2375/v1.41', # Optional (default: https://:2375)
]);

检查镜像是否存在

$exists = $docker->imageExists('436aed837ea2');
# true | false

$details = $docker->inspectImage('436aedXXXXXX');
# array | @throws Exception

API参考

测试过的Docker版本

许可证