Skip to content

on updating Docker service : cannot unmarshal array into Go value of type swarm.Resources #1

@rsalimian

Description

@rsalimian

I get this error when there is empty items in array:

json: cannot unmarshal array into Go value of type swarm.Resources

I'm trying to update service image. for that I have to first inspect current Service and then pull the whole Spec section then make my changed and then call the service update.

let say the JSON object is like:
`

{
"Name":"myservice",
"Labels":{
"com.df.distribute":"true",

        "com.df.notify":"true",
        "com.df.port":"80",
        "com.df.serviceDomain":"my.domain.com",
        "com.df.servicePath":"/"
    },
    "TaskTemplate":{
        "ContainerSpec":{
            "Image":"my/image:2.1.1"
        },
        "Resources":{
            "Limits":{
            },
            "Reservations":{
            }
        },
        "RestartPolicy":{
            "Condition":"any",
            "MaxAttempts":0
        },
        "Placement":{
            "Constraints":[
                "node.role==worker"
            ]
        },
        "Networks":[
            {
                "Target":"47ov8tcgvmuie3qhde3xfpb2y"
            },
            {
                "Target":"4naryq4iva5unmq1u5ye2z2tj"
            }
        ]
    },
    "Mode":{
        "Replicated":{
            "Replicas":2
        }
    },
    "UpdateConfig":{
        "Parallelism":1,
        "FailureAction":"pause"
    },
    "Networks":[
        {
            "Target":"proxy"
        },
        {
            "Target":"mynet"
        }
    ],
    "EndpointSpec":{
        "Mode":"vip"
    }
}

`

as you see in the JSON the Resource has empty arrays and if I take them off the API will works fine.

the point is using Curl command it works with no error and i dont need to remove emty items.

quick work around for this is that I have to process the array and remove all empty elements.
seems this is like GO error

Docker Version:
`
Client:
Version: 1.12.3-cs3
API version: 1.24
Go version: go1.6.3
Git commit: 781bb16
Built:
OS/Arch: linux/amd64

Server:
Version: 1.12.3-cs3
API version: 1.24
Go version: go1.6.3
Git commit: 781bb16
Built:
OS/Arch: linux/amd64
`

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