Jens,
TL;DR Yes, there are reasons why your entrypoint is not being used when the container service runs in swarm mode. It is possible I could make this work for you, but I would have to do it carefully to avoid breaking a lot of other commands.
In what follows, I will explain the issue in more detail than anyone really needs. I do this for my own good, because writing it all out is how I can come to understand it.
The APIs for Swarm and vanilla docker are not consistent in how they use entrypoints and commands and arguments. Check out this comment (
https://github.com/moby/moby/issues/29171#issuecomment-265274698) on a docker issue thread that gives a big table of the vanilla docker APIs used to define commands to run when creating containers (Image.Entrypoint and Image.Cmd) vs the Swarm APIs to define the command for a service (ContainerSpec.Command and ContainerSpec.Args). I will refer to those APIs throughout this post, so the table is very useful if not required for understanding the rest.
Let me break down how the container service resolves the command-line string and gets it into the container. First, we resolve the command-line string in the command using the arguments. Call that CMD. When we create the container (respectively, swarm service) we set the property Image.Cmd (resp. ContainerSpec.Command) to the list ["/bin/sh", "-c", "CMD"]. So we always execute the command within a shell.
That gets to the reason why your entrypoint is being overridden: because we use the Swarm API ContainerSpec.Command when creating the swarm service, the entrypoint will always be overridden. That's just how the API works.
However, there is more to the story. In the last version of the container service (1.4.0) I made a change that overrode the image entrypoint when launching containers in non-swarm mode as well. (I didn't publicize this much, but I probably should have, because it is a change that will likely impact commands.) The reason I did this is that the API I use to launch containers, Image.Cmd, meant there were problems running containers for images which have an entrypoint. For example, we'll call that entrypoint ENTRY. When not in swarm mode, the command that docker actually ends up executing is ENTRY /bin/sh -c CMD. That isn't what anyone wants.
So I made the decision to override the entrypoint when launching containers (though, again, what you are seeing in swarm mode is not related to my decision, it is just a natural consequence of the APIs used to create swarm services) with the assumption that whatever had been the entrypoint on the image would simply be made explicit in the command's command-line string.
But that may not have been the right decision!
Now that I have typed this all out, I can see another way things could maybe, possibly work. Instead of doing what I currently do, which is...
* Non-swarm: Image.Cmd = /bin/sh -c CMD, Image.Entrypoint = "" <--- using an empty string explicitly overrides the entrypoint
* Swarm: ContainerSpec.Command = /bin/sh -c CMD, ContainerSpec.Args = null
I could do this...
* Non-swarm: Image.Cmd = CMD, Image.Entrypoint = null <--- using null leaves image entrypoint intact
* Swarm: ContainerSpec.Command = null, ContainerSpec.Args = CMD
In the new way, if an entrypoint is set, it gets used. Everything in the resolved command-line string gets passed to it as arguments. If an entrypoint is not set, it gets the default value of /bin/sh -c. What gets executed is /bin/sh -c CMD. So that's equivalent to what I am already doing anyway!
The only other issue is when an image has an entrypoint set, but the person writing the command does not want to use it. I have to consider whether to allow command authors to explicitly, knowingly override the entrypoint by setting a property in the command.
Sorry that your stuff isn't working. I'll see what I can do to fix it. Give me a few days to clear a couple other things off my plate, and I will play with this issue a little.
Flavin