Docker 101 : CPU and Memory limits for containers - cpu-shares, memory -

Container's logs:

Containers sometimes exit without a hint of what went wrong.
One way of investigating the issue, is to look at the logs using the below command:

Docker keep the logs for the containers in the system as long as the container is not deleted.

Deleting a container:

The below command runs a container named "debian-image" based on a "debian" image":

To delete a container, we need to stop it first using the below:

Then we remove it using the below command:

Limiting memory for containers:

we can limit the amount of memory a container can use using the command:

--memory: Could be 200m for two hundred megabytes or 1g for one gigabyte for example.

CPU limits:

The "
--cpu-shares" parameter gives the container access to a portion of the CPU cycles of the machine.

Below is an example using the "--cpu-shares" parameter:

The default value is 1024.
We go above the default value or below it to gives the container access to more or less CPU cycles.


The "--cpu-shares" is a limit that is enforced only when the system resources become scarce.

Another way to limit CPU use is with the "--cpu" parameter:

We could use --cpus="1.5" or --cpus="2.5" for a system that has at least three CPUs.
The "--cpu" value is always fulfilled even if the system resources run low.


Leave as a comment: