Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while create network with dockerode-compose #44

Open
VintaGist opened this issue Apr 25, 2024 · 0 comments
Open

Error while create network with dockerode-compose #44

VintaGist opened this issue Apr 25, 2024 · 0 comments

Comments

@VintaGist
Copy link

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant