Git Product home page Git Product logo

docklet's Introduction

Docklet

A docker client for PHP. The main goal of this library is to mimic the docker shell client with its command-based API. This allows shell gurus save time by skipping learning a new library API.

Another vision is to make this library cross-version compatible. Use the same PHP docker client with any docker server version. The library docker-php is developed and tested against one single docker version. That library relies on a specific version. docklet, however, doesn't support cross-version compatibility yet but it has the potential by versioning the commands and its options. As of now docklet is developed against API version 0.14 but in future versions docklet will detect the server version and make the right API call.

Run ls in a container

<?php

include('../vendor/autoload.php');

use Docklet\Docker;
use Docklet\Command\Run;

// 1. Create a new Docker client
//$docker = new Docker('unix:///var/run/docker.sock');
$docker = new Docker('tcp://127.0.0.1:9999');

// 2. Create the config for the run command
$options = Run::options('slopjong/apache:latest', 'ls');

// 3. Run a container
$json = $docker->run($options);

// 4. Output the result(s)
$stdObj = json_decode($json);

if (count($stdObj->LastCmdOutput)) {
    foreach ($stdObj->LastCmdOutput as $output) {
        echo $output;
    }
}

Run a web server in a container

<?php

include('../vendor/autoload.php');

use Docklet\Docker;
use Docklet\Command\Run;

// 1. Create a new Docker client
//$docker = new Docker('unix:///var/run/docker.sock');
$docker = new Docker('tcp://127.0.0.1:9999');

// 2. Create the config for the run command
$command = array(
    '/usr/sbin/apache2ctl',
    '-D',
    'FOREGROUND',
);

$options = Run::options('slopjong/apache', $command)
    ->portBinding('80', '8999')
    ->daemon(true);

// 3. Run a container and point your browser to http://localhost:8999
$json = $docker->run($options);

// 4. Output the container ID
$stdObj = json_decode($json);

// 5. Stop the container after 10 seconds
$docker->stop($stdObj->Id, 10);

docklet's People

Contributors

slopjong avatar

Watchers

 avatar  avatar

Forkers

panahbiru

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.