Set CPU limitation to Docker containers

Docker inherits the Linux CGroups notion of CPU shares (by default it is 1024 shared weight units).
A relative weight can be expressed - run the container on 4 CPUs on 50% shared weight units:

docker run -it --rm -c 512 nginx --cpus 4

Pin a container to run on specific CPUs - cores 0 and 2 only (2 CPUs):
docker run -it --rm --cpuset-cpus=0,2 busybox --cpus 2 dd if=/dev/zero of=/dev/null