Skip to content

Error while create network with dockerode-compose #44

@VintaGist

Description

@VintaGist

dockerode-compose will not work if docker-compose.yml file have small section networks:

version: "3"

services:
    ...
    networks:
            - any_net

networks:
    any_net:
        driver: "bridge"
        ipam:
            config:
                - subnet: "172.143.0.0/16"

This configuration generates an error:

Error: (HTTP code 400) unexpected - invalid JSON: json: cannot unmarshal object into Go struct field IPAM.IPAM.Config of type []network.IPAMConfig

This is due to incorrect parameters being generated for docker.createNetwork() in the lib/network.js file

For example :
line 49:

var opts = {
       Name: projectName + '_' + networkName,
       Driver: network.driver,
       DriverOpts: network.driver_opts, //unsetted in docker-compose.yml
       Labels: {
         ...network.labels,
         ...{
           'com.docker.compose.network': 'default',
           'com.docker.compose.project': projectName,
         },
       },
       Attachable: network.attachable, //may be unsetted in docker-compose.yml
       EnableIPv6: network.enable_ipv6, //may be unsetted in docker-compose.yml
       Internal: network.internal, //may be unsetted in docker-compose.yml
       CheckDuplicate: true,
     };

line 69

opts.IPAM = {
         Driver: network.ipam.driver, //may be unsetted in docker-compose.yml
         Options: network.ipam.options, //may be unsetted in docker-compose.yml
       };

line 74

   opts.IPAM['Config'] = {
           Subnet: network.ipam.config.subnet, // network.ipam.config - its an array! .subnet may be unsetted
           IPRange: network.ipam.config.ip_range, // network.ipam.config - its an array! .ip_range may be unsetted
           Gateway: network.ipam.config.gateway,  // network.ipam.config - its an array! .gateway may be unsetted
           AuxAddress: network.ipam.config.aux_addresses, // network.ipam.config - its an array! .aux_addresses may be unsetted
         };

For the correct parameters for creating a network with Dockerode, see the Docerode tests:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions