NAME

Docker::Client - Docker client based on official OpenAPI specs

SYNOPSIS

use Docker::Client;

my $client = Docker::Client->new();

my $tx = $client->ContainerCreate(
    {},
    json => {
        Image        => 'ubuntu',
        AttachStdin  => 0,
        AttachStdout => 1,
        AttachStderr => 1,
        Tty          => 1,
        Cmd          => [ '/bin/bash', '-c', 'tail -f /etc/resolv.conf' ],
        OpenStdin    => 0,
        StdinOnce    => 0
    }
);

my $container = $ctx->result()->json();

$tx = $client->ContainerStart( { id => $container->{Id} } );
if ( !$tx->result()->is_success() ) {
    ...
}

## Getting container logs
$client->api()->on(
    after_build_tx => sub {
        my ( $ua, $tx ) = @_;

        $tx->res()->content()->unsubscribe('read')->on(
            read => sub {
                my ( $content, $bytes ) = @_;
                
                say $bytes;
            }
        );
    }
);

$client->ContainerLogs(
    {
        id     => $container->{Id},
        stderr => 1,
        stdout => 1,
        follow => 1,
    }
);

$client->api()->unsubscribe('after_build_tx');

## Stopping the container
$tx = $client->ContainerStop( { id => $container->{Id} } );
if ( !$tx->result()->is_success() ) {
    ...
}

DESCRIPTION

This module is built on top of OpenAPI::Client and the official OpenAPI specifications from docker.com. It supports multiple versions of Docker API, and in the local context, it doesn't require exposing the Docker API server on a TCP socket as it makes use of the "/var/run/docker.sock" file. Under the hood the all requests are handled by a Mojo::UserAgent instance, which is highly configurable.

This module is EXPERIMENTAL, the methods are subject to change. In the future, I might hide all API calls under custom-methods implementations to resemble a high-level API; also, I welcome any suggestions.

ATTRIBUTES

endpoint

The Docker REST endpoint. Defaults to 'http+unix://var/run/docker.sock'.

version

The Docker OpenAPI spec version. Defaults to 'v1.40', lower value supported is 'v1.25'.

ua

The Mojo::UserAgent object used to perform the requests.

METHODS

All methods are generated from the OpenAPI spec upon class instantiation and have the same name as the OperationId property.

MethodName

my $tx = $client->MethodName( \%params, %content );

Returns a Mojo::HTTP::Transation object which contains the response with some additional features.

MethodName_p

my $promise = $client->MethodName_p( \%params, %content );
$promise->then(sub { 
    my $tx = shift;
    ...
});

Same as above, but returning a Mojo::Promise object.

For the latest version (1.40) the methods are:

  • ContainerList

  • ContainerCreate

  • ContainerInspect

  • ContainerTop

  • ContainerLogs

  • ContainerChanges

  • ContainerExport

  • ContainerStats

  • ContainerResize

  • ContainerStart

  • ContainerStop

  • ContainerRestart

  • ContainerKill

  • ContainerUpdate

  • ContainerRename

  • ContainerPause

  • ContainerUnpause

  • ContainerAttach

  • ContainerAttachWebsocket

  • ContainerWait

  • ContainerDelete

  • ContainerArchiveInfo

  • ContainerArchive

  • PutContainerArchive

  • ContainerPrune

  • ImageList

  • ImageBuild

  • BuildPrune

  • ImageCreate

  • ImageInspect

  • ImageHistory

  • ImagePush

  • ImageTag

  • ImageDelete

  • ImageSearch

  • ImagePrune

  • SystemAuth

  • SystemInfo

  • SystemVersion

  • SystemPing

  • SystemPingHead

  • ImageCommit

  • SystemEvents

  • SystemDataUsage

  • ImageGet

  • ImageGetAll

  • ImageLoad

  • ContainerExec

  • ExecStart

  • ExecResize

  • ExecInspect

  • VolumeList

  • VolumeCreate

  • VolumeInspect

  • VolumeDelete

  • VolumePrune

  • NetworkList

  • NetworkInspect

  • NetworkDelete

  • NetworkCreate

  • NetworkConnect

  • NetworkDisconnect

  • NetworkPrune

  • PluginList

  • GetPluginPrivileges

  • PluginPull

  • PluginInspect

  • PluginDelete

  • PluginEnable

  • PluginDisable

  • PluginUpgrade

  • PluginCreate

  • PluginPush

  • PluginSet

  • NodeList

  • NodeInspect

  • NodeDelete

  • NodeUpdate

  • SwarmInspect

  • SwarmInit

  • SwarmJoin

  • SwarmLeave

  • SwarmUpdate

  • SwarmUnlockkey

  • SwarmUnlock

  • ServiceList

  • ServiceCreate

  • ServiceInspect

  • ServiceDelete

  • ServiceUpdate

  • ServiceLogs

  • TaskList

  • TaskInspect

  • TaskLogs

  • SecretList

  • SecretCreate

  • SecretInspect

  • SecretDelete

  • SecretUpdate

  • ConfigList

  • ConfigCreate

  • ConfigInspect

  • ConfigDelete

  • ConfigUpdate

  • DistributionInspect

  • Session

AUTHOR

Tudor Marghidanu tudor@marghidanu.com

COPYRIGHT AND LICENSE

Copyright (c) 2020, Tudor Marghidanu.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.