Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set resources allocated to a container using docker?

Tags:

docker

As the title of this question suggests I'm wanting to set max disk/memory and cpu usage for a container using docker (docker.io).

Is there a way to do this using just docker?

like image 690
rmc Avatar asked Apr 18 '13 13:04

rmc


People also ask

What is the default memory allocated to docker container?

By default, the container can swap the same amount of assigned memory, which means that the overall hard limit would be around 256m when you set --memory 128m .

How do you attach volumes to a container?

To mount a data volume to a container add the --mount flag to the docker run command. It adds the volume to the specified container, where it stores the data produced inside the virtual environment. Replace [path_in_container] with the path where you want to place the data volume in the container.


1 Answers

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
like image 153
Thanh DK Avatar answered Oct 11 '22 11:10

Thanh DK