In plain docker you can achieve each of the limit with command line options:
A container can be limited to a single CPU core (or a hyperthread on current intel hardware):
docker run \
--cpus 1 \
image
or limited by Dockers CPU shares, which default to 1024. This will only help if most of your tasks that are being slowed down are also in Docker containers, so they are being allocated Dockers shares as well.
docker run \
--cpu-shares 512 \
image
Limiting memory is a bit finicky as your process will just crash if it hits the limit.
docker run \
--memory-reservation 2000 \
--memory 2048 \
--memory-swap 2048 \
image
Block or Device IO is more important than total space for performance. This can be limited per device, so if you keep data on a specific device for your conversion:
docker run \
--volume /something/on/sda:/conversion \
--device-read-bps /dev/sda:2mb \
--device-read-iops /dev/sda:1024 \
--device-write-bps /dev/sda:2mb \
--device-write-iops /dev/sda:1024 \
image
If you want to limit total disk usage as well, you will need to have the correct storage setup. Quotas are supported on the devicemapper
, btrfs
and zfs
storage drivers, and also with the overlay2
driver when used on an xfs
file system that is mounted with the pquota
option.
docker run \
--storage-opt size=120G
image
Compose/Service
Docker compose v3 seems to have abstracted some of these concepts away to what can be applied to a service/swarm so you don't get the same fine grained control.
For a v3 file, use the resources
object to configure limits
and reservations
for cpu and memory:
services:
blah:
image: blah
deploy:
resources:
limits:
cpu: 1
memory: 2048M
reservations:
memory: 2000M
Disk based limits might need a volume driver that supports setting limits.
If you can go back to a v2.2 Compose file you can use the full range of constraints on a container at the base level of the service which are analogous to the docker run
options:
cpu_count
, cpu_percent
, cpu_shares
, cpu_quota
, cpus
, cpuset
, mem_limit
, memswap_limit
, mem_swappiness
, mem_reservation
, oom_score_adj
, shm_size