Docker Community Forums

Share and learn in the Docker community.

Docker compose V3 linux core isolation/cpu pinning

Hi, all

I’m working for a high frequency trading firm and trying to get a docker compose stack to respect core isolation or pin containers to specific cores.

Basically, the option we have on docker-compose V3 to limit the amount of CPU(s) a docker container can use isn’t enough. I need to be able to set it to either use a specific list of cores, or avoid doing anything at all with a specific set of cores. Anything else increases latency on executing commands (and causes our current applications to fail)

Does anyone know how this can be done? I can see docker run does it ( --cpuset-cpus) and Kubernetes does it ( and docker-compose used to do it. (in V2)

I you do docker-compose deployments, then the compose reference v2 is the way to go. v3+ is aimed for swarm stack deployments. Surely v3 “works” for docker-compose deployments as well, BUT while adding swarm deployment specific features, it removes a lot of docker-compose specific features, especialy those that address ressources, privliged mode, capabilities, ulimits,… all the “low level” stuff simple containers don’t require. If you need to control those features and require multi node deployments, there is no way arround kubernetes. If single node deployments are everything you will ever need, you can stick to docker-compose and the last compose ref v2 version (which should be 2.4).

The compose ref 2.2 added cpuset, which should do what you are looking for.

Swarm services are very limited compared to plain docker containers (which docker-compose creates as well), see: If a feature is marked as checked, make sure to verify in which docker version it is available, as some of these checked features are not even available with the latest stable 19.03.13. Also not every feature added to the service command necessarily has a counterpart in the current version of the docker file reference v3.