定制 idrislab/laravel-docker-containers 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

idrislab/laravel-docker-containers

Composer 安装命令:

composer require idrislab/laravel-docker-containers

包简介

Automate your docker containers with artisan

README 文档

README

Automate your docker containers inside Laravel

Setup

Requirements

Docker >= 1.13

Laravel >= 5.3.*

PHP >= 5.6.4

Installation

composer require idrislab/laravel-docker-containers

Set the following environment variable(inside your .env file)

DOCKER_SOCKET=unix:///var/run/docker.sock

Create a new Artisan command

php artisan make:command Containers

Register the new command with Artisan in app/Console/Kernel.php

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

Update your Containers command to register containers shipped by default

<?php

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,
    ];
}

Usage

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

Examples

Starting all containers

php artisan containers start

Stopping and starting multiple containers

php artisan containers start mysql redis

Stopping one container

php artisan containers stop mysql

Adding custom containers

Create a directory inside app/ named Containers and create a file named MySQLGroupReplication.php with the following:

<?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');
    }
}

Update your app/Console/Commands/Containers.php command to register the new container

<?php

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,
    ];
}

Start your container

php artisan containers start mysqlgroupreplication

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固