0

There's two distinct parameters in the /services/create endpoint, called Command and Args. The description says:

  • Command (array of string) – the command to be run in the image
  • Args (array of string) – arguments to the command

I was puzzled by the fact that Command is an array: if the command arguments can be passed to it (which seems to be the case as docker-py splits it as a shell command) what's the purpose of Args then?

Ale
  • 1,998
  • 19
  • 31

1 Answers1

0

My current guess: the purpose of Command and Args is the same as in Entrypoint and Cmd in regular Docker containers. Args are just appended to the Command:

POST /services/create

{
  "Name": "test",
  "TaskTemplate": {
    "ContainerSpec": {
      "Image": "ubuntu",
      "Command": ["echo", "foo"],
      "Args": ["bar"]
    }
  }
}
$ docker service logs test
test.1.npltmr9c69fz@hostname    | foo bar

And if you omit the Command, it is taken from the image's entrypoint:

POST /services/create

{
  "Name": "test2",
  "TaskTemplate": {
    "ContainerSpec": {
      "Image": "ubuntu",
      "Args": ["echo", "baz!"]
    }
  }
}
$ docker service logs test2
test2.1.c16waqqxtdgd@hostname    | baz!

This is only a result of my empirical testing, so any solid documentation / source code proofs are appreciated!

Ale
  • 1,998
  • 19
  • 31
  • 1
    (Kubernetes has the same "`command` is entrypoint, `args` is command" renaming; frequently an image will use `ENTRYPOINT` to do first-time setup and it's useful to just pass a command as `args`.) – David Maze Jun 05 '20 at 01:04