4eixos / eixo-docker

Suite of Perl modules to interact with Docker
Apache License 2.0
18 stars 4 forks source link

Can't Enabeling network. #12

Open SIM0N-F opened 7 years ago

SIM0N-F commented 7 years ago

Hello,

I try make little script to build and start my PHP docker, for the moment my script is pretty simple but he stop working when I want enable network.

My script:

use Data::Dumper;
use Eixo::Docker::Api;

# getAll
my $lista = $a->containers->getAll();

my $c = $a->containers->create(
        Hostname => 'test',
        Cmd => ["nc", "-l", '0.0.0.0', '80'],
        Image => "trafex/alpine-nginx-php7",
        Name => "php7",
        NetworkDisabled => "False",
        ExposedPorts => {
            "80/tcp" =>  {}
        },
);

my $container = $a->containers->getByName("php7");
$container->start(
         "PortBinding" => {
                 "80/tcp" =>  [{"HostIp" =>  "0.0.0.0", "HostPort" =>  "8080" }]
         },
);      

I have :

Eixo::Docker::ContainerException=HASH(0x3044888)

Could you help me please?

Many thanks by advance, Simon.

SIM0N-F commented 7 years ago

It's now OK for me :

I have add eval() for debug and I had this error :

'error_details' => 'Error produced in \'postContainers\' api call. Details: 500 - {"message":"json: cannot unmarshal string into Go value of type bool"}'

So i have changed NetworkDisabled => "False", to NetworkDisabled => \0,

I also change 'portbinding' for 'portbindings' and added the bindings arguments in create function.

use strict;
use Data::Dumper;
use Eixo::Docker::Api;

my $a = Eixo::Docker::Api->new('http://127.0.0.1:4243');

# getAll
my $lista = $a->containers->getAll();

eval {
my $c = $a->containers->create(
        Hostname => 'test',
        Image => "trafex/alpine-nginx-php7",
        Name => "php7",
        NetworkDisabled => \0,
        ExposedPorts => {
            "80/tcp" =>  {}
        },
        HostConfig => {
          "PortBindings" => { "80/tcp" => [{"HostIp" => "0.0.0.0", "HostPort" => "8100" }] },
        },
);

my $container = $a->containers->getByName("php7");
$container->start(
         "PortBindings" => { "80/tcp"=> [{"HostPort" => "80" }] },
);

};

print Dumper($@) if($@);
~