Docker Swarm Scale Service using update API

I am using docker service api to scale the number of replicas, however it is returning an error related to version, I tried to pass the version which was returned in the service inspect api, it didn’t help getting the same error message. Anyone has luck with service update api to scale the number of containers.

curl -v -XPOST http://:2375/services/SERVICE-ID/update -d @service-update.json

Request Content:
{
“Name”: “SERVICE-NAME”,
“ID” : “SERVICE-ID”,
“TaskTemplate”: {
“ContainerSpec”: {
“Image”: “IMAGE-NAME”
}
},
“Mode”: {
“Replicated”: {
“Replicas”: 5
}
},
“UpdateConfig”: {
“Parallelism”: 1
},
“EndpointSpec”: {
“Mode”: “vip”
},
}

Response:
< HTTP/1.1 500 Internal Server Error
{“message”:“Invalid service version ‘’: strconv.ParseUint: parsing “”: invalid syntax”}

1 Like

Got the same error.

The creation API with same is succeed

instead of curl -v -XPOST http://:2375/services/SERVICE-ID/update -d @service-update.json shouldn’t it be curl -v -XPOST http://:2375/v1.24/services/SERVICE-ID/update -d @service-update.json if you want to use v1.24, which is the latest version for Docker 1.12.0

I tried with /v1.24 and still get
{
“message”: “Invalid service version ‘’: strconv.ParseUint: parsing “”: invalid syntax”
}

Docker version is like below:

Client:
Version: 1.12.0
API version: 1.24
Go version: go1.6.3
Git commit: 8eab29e
Built: Thu Jul 28 22:11:10 2016
OS/Arch: linux/amd64

Server:
Version: 1.12.0
API version: 1.24
Go version: go1.6.3
Git commit: 8eab29e
Built: Thu Jul 28 22:11:10 2016
OS/Arch: linux/amd64

Sorry for disturbing. I forget to add the version parameter.

After I add ?version=11 in the url, the curl return 200

1 Like

Adding v1.24 to the URL didn’t help me out. getting the same error message.

But adding version as the query parameters, raised different error.
{“message”:“rpc error: code = 2 desc = update out of sequence”}

What will be significance of version parameter. Do we need to check the version parameter of service that we are trying to update. I have tried using the version parameter from service inspect command and it worked fine.

docker service inspect SERVICE-ID
“Version”: {
“Index”: 97891
}

Where did it specified that we need to use version parameters from inspect as a query parameter for Update API. can you please point to the documentation. I couldn’t able to find the API documentation.

But adding version=VERSION_FROM_INSPECT_SERVICE has worked fine. I have received 200 OK response back.

Update API is not retaining any environment variables or container labels, which were passed during service creation. It looks like we need to send all these parameters again with service update API.

{
“Name”: “SERVICE-NAME”,
“TaskTemplate”: {
“ContainerSpec”: {
“Image”: “IMAGE-NAME”
}
},
“Mode”: {
“Replicated”: {
“Replicas”: 6
}
}
}

I have used the above request json file to send for the update api command, it removed all the existing environment variables, container labels, service labels which I have used during the service creation part. Are you guys also facing the same issue. Is there any way that I can inform update API to not to remove any existing information. Currently my usecase is I want to scale up the service using update API command.

The command line seems to have similar problem. When you update with only CPU limitation, other limitation will be updated to empty.

Not sure when docker will fix this.

Hello everyone.

It isn’t a docker bug but it is a mistake.

You must pass to service a correct “configuration version” of your servic!!!

This is an example:

GET /services/3t5nqz19fsar9vpuvtqgrifak

swarm response a JSON like:

"ID": "3t5nqz19fsar9vpuvtqgrifak",
  "Version": {
    "Index": 276551
  },

Now you can update swarm service with POST /services/3t5nqz19fsar9vpuvtqgrifak?version=276551

Kings regards!!!

thanks guys, I was stuck on update service for 2 weeks.

I found that (at least for me):

  • update service using service name won’t work (service not found error) and have to use FULL service ID
  • first I need to inspect service to pull whole “Spec”
  • use current version.index to use in service update
  • update it with changes and use it to update service

This is the bare minimum to scale the service using the update endpoint:

1- use service id or name
2- use correct version (inspect first to get Version.Index
3- Should supply at least: name and image.

Example:

Get latest version of service:

curl http://localhost:1234/v1.24/services/nginx | jq ".Version.Index"
> 405

Send the update request:

curl http://localhost:1234/v1.24/services/nginx/update?version=405 -d @json

where ‘json’ file has this content:

{
  "Name": "nginx",
  "TaskTemplate": {
    "ContainerSpec": {
      "Image": "nginx:latest@sha256:adea4f68096fded167603ba6663ed615a80e090da68eb3c9e2508c15c8368401"
    }
  },
  "Mode": {
    "Replicated": {
      "Replicas": 8
    }
  }
}