PHP code example of idrislab / laravel-docker-containers

1. Go to this page and download the library: Download idrislab/laravel-docker-containers 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/ */

    

idrislab / laravel-docker-containers example snippets


protected $commands = [
       Commands\Containers::class,
  ];



namespace App\Console\Commands;

use luisgros\docker\containers\MySQL;
use luisgros\docker\containers\Redis;
use luisgros\docker\ContainersCommand;

class Containers extends ContainersCommand
{
    protected $containers = [
        MySQL::class,
        Redis::class,
    ];
}



namespace App\Console\Commands;

use App\Containers\MySQLGroupReplication;
use luisgros\docker\containers\MySQL;
use luisgros\docker\containers\Redis;
use luisgros\docker\ContainersCommand;

class Containers extends ContainersCommand
{
    protected $containers = [
        MySQL::class,
        Redis::class,
        MySQLGroupReplication::class,
    ];
}
sh
php artisan make:command Containers

php artisan containers <start|stop|restart> [container(s)]
sh
php artisan containers start
sh
php artisan containers start mysql redis
sh
php artisan containers stop mysql
 php

namespace App\Containers;

use luisgros\docker\containers\Container;

class MySQLGroupReplication extends Container
{
    /**
     * @var string
     */
    public $repo = 'mysql/mysql-gr';
    /**
     * @var string
     */
    public $tag = 'latest';
    /**
     * @var string
     */
    public $network = 'group1';
    /**
     * @var string
     */
    public $instances = 3;

    /**
     * @return array
     */
    public function runCommand()
    {
        return [
                '-d --rm --net=group1 -e MYSQL_ROOT_PASSWORD=ENV[DB_PASSWORD] \\'.
                '-e MYSQL_REPLICATION_USER=ENV[DB_PASSWORD] -e MYSQL_REPLICATION_PASSWORD=ENV[DB_PASSWORD] \\'.
                'mysql/mysql-gr --group_replication_group_seeds=\'ENV[CONTAINER_I2]:6606,ENV[CONTAINER_I3]:6606\' \\'.
                '--server-id=ENV[INSTANCE_ID]',

                '-d --rm --net=group1 -e MYSQL_ROOT_PASSWORD=ENV[DB_PASSWORD] \\'.
                '-e MYSQL_REPLICATION_USER=ENV[DB_PASSWORD] -e MYSQL_REPLICATION_PASSWORD=ENV[DB_PASSWORD] \\'.
                'mysql/mysql-gr --group_replication_group_seeds=\'ENV[CONTAINER_I1]:6606,ENV[CONTAINER_I3]:6606\' \\'.
                '--server-id=ENV[INSTANCE_ID]',

                '-d --rm --net=group1 -e MYSQL_ROOT_PASSWORD=ENV[DB_PASSWORD] \\'.
                '-e MYSQL_REPLICATION_USER=ENV[DB_PASSWORD] -e MYSQL_REPLICATION_PASSWORD=ENV[DB_PASSWORD] \\'.
                'mysql/mysql-gr --group_replication_group_seeds=\'ENV[CONTAINER_I1]:6606,ENV[CONTAINER_I2]:6606\' \\'.
                '--server-id=ENV[INSTANCE_ID]',
        ];
    }

    public function preCommand()
    {
        $this->docker('network create group1 &>/dev/null');
    }
}
sh
php artisan containers start mysqlgroupreplication