PHP code example of utopia-php / orchestration

1. Go to this page and download the library: Download utopia-php/orchestration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

utopia-php / orchestration example snippets




topia\Orchestration\Orchestration;
use Utopia\Orchestration\Adapter\DockerCLI;

// Initialise Orchestration with Docker CLI adapter.
$orchestration = new Orchestration(new DockerCLI());

// Pull the image.
$orchestration->pull('ubuntu:latest');

// Launch a ubuntu container that doesn't end using the tail command.
$containerID = $orchestration->run('ubuntu:latest', 'testContainer', ['tail', '-f', '/dev/null']);

$stderr = '';
$stdout = '';

// Execute a hello world command in the container
$orchestration->execute($containerID, ['echo', 'Hello World!'], $stdout, $stderr);

// Remove the container forcefully since it's still running.
$orchestration->remove($containerID, true);

    use Utopia\Orchestration\Orchestration;
    use Utopia\Orchestration\Adapter\DockerAPI;

    $orchestration = new Orchestration(new DockerAPI($username, $password, $email));
    

    use Utopia\Orchestration\Orchestration;
    use Utopia\Orchestration\Adapter\DockerCLI;

    $orchestration = new Orchestration(new DockerCLI($username, $password));
    

    $orchestration->pull('image:tag');
    

    $orchestration->run(
        'image:tag',
        'name',
        ['echo', 'hello world!'],
        'entrypoint',
        'workdir',
        ['tmp:/tmp:rw', 'cooldirectory:/home/folder:rw'],
        ['ENV_VAR' => 'value'],
        '/tmp',
        ['label' => 'value'],
        'hostname',
        true,
    );
    

    $stdout = '';
    $stderr = '';

    $orchestraton->execute(
        'container_id',
        ['echo', 'Hello World!'],
        $stdout,
        $stderr,
        ['VAR' => 'VALUE'],
        10,
    )
    

    $orchestration->remove('container_id', true);
    

    $orchestration->list(['label' => 'value']);
    

    $orchestration->listNetworks();
    

    $orchestration->createNetwork('name', false);
    

    $orchestration->removeNetwork('network_id');
    

    $orchestration->connect('container_id', 'network_id');
    

    $orchestration->disconnect('container_id', 'network_id', false);
    
bash
composer