One runaway container can make a small home server feel dead. I would rather give the greedy ones a ceiling, and --cpus is the readable way to do it.
The flag takes a number of CPUs, fractions allowed. The resource constraints page uses a two-CPU host as its example: --cpus="1.5" means the container can use at most one and a half CPUs. It is shorthand for --cpu-period=100000 --cpu-quota=150000, so you never have to do that math yourself.
docker run -d --name encoder --cpus="1.5" example/app:1.0
You can also change it on a container that already exists, without recreating it:
docker update --cpus="0.5" encoder
In Compose the matching service attribute is cpus: 1.5, and the reference says 0.000 means no limit.
--cpus is a hard ceiling, so the container is throttled even when the rest of the machine is idle. If you only want to give some containers priority when the CPU is busy, --cpu-shares is the soft version: a relative weight with a default of 1024 that only matters when there is contention. I use the ceiling for jobs that should never hog the machine and shares for the rest.
Check the effect with docker stats --no-stream while the container is busy.
Further reading: Resource constraints, docker run reference