I'm deploying a stack file with couple services (each service has only 1 replica) and I need to limit each container to use a different subset of CPU cores. I found online here that cpuset is not supported with swarm's stack file (compose v3). I tried cpu limit but this will only specify a percentage of cpu resources not cores. Is there a work around for this case? I need cores assignment to support software licensing restrictions.
Unfortunately and as you already found out, there is no way (yet) to restrict a task to a given core or group of cores running swarm mode with stacks and/or services.
A reasonable option would be to manually start those containers on the machines you wish them to run onto, bypassing Swarm in the process. Thus using your machines as "plain-old" docker daemons and using the --cpuset-cpus
flag.
The only catch is that containers, by default, get access to all cpus, unless it's restricted with the flag mentioned above for a single container. Thus you need to be careful and exclude those nodes from your Swarm, otherwise it will schedule containers and use the cores you wished to be restricted for your licensed software.
Another option is to run the old Swarm which does support the --cpuset-cpus
flag. So you could run an old Swarm on top of your docker fleet managed with Swarm mode. Just make sure that the machines hosting your pinned and cpu-restricted containers are not accessed by Swarm mode, the following could be an option for example:
+-------------+
| Swarm Mode |
+----------------+ Primary |
| | |
| +------+------+
| |
| |
| | +----------------+
| | | Containers |
| | | with |
| | | pinned cores |
+------v------+ +------v------+ +------+------+---------+
| | | | | |
| Agent | | Agent | | Agent |
| | | | | |
+------+------+ +------^------+ +------^------+
^ | |
| | |
| | |
| | |
| | |
| | |
| +------+------+ |
| | Swarm | |
+----------------+ Primary +----------------+
| |
+-------------+
To conclude, there is no reasonable workaround as of now using Docker Swarm mode only. There might still be hope to see this land in the future eventually.