How do I set resources allocated to a container using docker?
Memory/CPU
Docker now supports more resource allocation options:
- CPU shares, via -c flag
- Memory limit, via -m flag
- Specific CPU cores, via --cpuset flag
Have a look at docker run --help
for more details.
If you use lxc backend (docker -d --exec-driver=lxc
), more fine grained resource allocation schemes can be specified, e.g.:
docker run --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"\
--lxc-conf="lxc.cgroup.cpu.shares = 1234"
Storage
Limiting storage is a bit trickier at the moment. Please refer to the following links for more details:
- Resizing Docker containers with the Device Mapper plugin
- Question on Resource Limits?
- devicemapper - a storage backend based on Device Mapper
You can now allocate a number of CPU shares to a container with the -c option as described here