When you create a docker container
there is no way to assign resources to it like RAM
, disco duro
, etc. The only thing I have seen is how to open ports so that there is communication with the outside ( see here ) and also how to add volumes ( see here ) to store or read files.
But I haven't found a way to manage the resources of a docker container
, does anyone know if that's possible? are there default values? Do they grow automatically depending on demand? can they be restricted?
I've searched the official documentation but haven't found anything related.
What you are looking for is the reference for
run
which is here . In direct response copying the examples in the documentation:Allocate RAM (memory)
With memory limit up to 300MB and no swap
With memory limit and with all the swap that is available:
There are a multitude of other options in the documentation (limit swap, etc). Look at the reference I gave above.
assign hard drive
From version 1.9.1. it is possible to limit the hard disk usage directly (in response to incident #3804 where you will find the history of this functionality). I haven't used it myself, but according to the documentation it would have the following form:
If possible, you can manage it in the following ways:
1) If you are using the most recent version of docker for windows (docker-for-windows) or for Mac (docker-for-mac) you can locate the whale icon (characteristic of docker) in the task bar, right click on the icon and select settings. Once this is done, the interface will appear to assign resources to the application.
2) You can use the docker command to allocate resources as follows:
2.1) By the name of the container:
Description: In the previous command we are assigning 2 Gigs of RAM memory and 2 cores to the "whale" container. Inside the "<>" is placed the name of the container that can be observed through the command
docker ps
. The name must be placed without the "<>" symbols as they are only there to reference where the name is placed.2.2) By the "id" of the container:
Description: similar to 2.1) allocate 1 Gig of ram and 4 cores to container id "0dca4f7e27a6" for example. Take into account that the "<>" symbols should not go when executing the command either.
3) If you are running docker through virtual box (older versions than docker-for-windows) for example the "Docker Toolbox" you can reallocate the resources through the configuration option offered by the same virtual machine.
Note: The process can also be performed for users using VMware with docker (VMware driver).
4) If for example you use Virtualbox and you want to assign resources by commands you can try:
Note: The changes will be executed in "whale"
The minimum "default" value for RAM memory is 4m (4 megabyte), if a fixed value is assigned (for example 3Gb) docker will adjust to the maximum value and if no value is assigned, the RAM consumption will increase as the container requires more resources. The same happens with all other resources such as the number of cores for example. For more information about the default values and their limits, you can visit the official docker documentation.
I hope to be helpful. All the best!