Technical work, should be praised and then see, form a habitCopy the code

Docker use tutorial related series of directories


Container resource constraints are applied when creating containers

Memory limit

-m containers can use the maximum amount of memory

-memory-swap Specifies the amount of memory that can be swapped to a disk

-oom -kill -disable Disables oom killer

docker run -d -i -t --name=nginx01 -m="500m" --memory-swap="600m" --oom-kill-disable  nginx /bin/bash
Copy the code

Analysis 1: -m=”500m” –memory-swap=” 600M “Meaning that the maximum memory size can be 500m and the swap size can be 100M

Analysis 2: -m=”500m” –memory-swap=”500m” meaning: the maximum memory size can be 500m. Swap is disabled

Analysis 3: -m=”500m” meaning: the maximum amount of memory that can be used is 500m, and the maximum amount of memory that can be used is 1000M(twice the maximum amount of memory).

Analysis 4: -m=”500m” –memory-swap=”-1″ meaning: can use the maximum memory 500m, the largest swap

See the resources

docker stats --no-stream nginx01
Copy the code

If there is no limit, the maximum amount of memory is used

 

CPU limit

-cpus Indicates the maximum number of cpus that can be used

First check the system CPU is a few cores, I this is 1 core

top
Copy the code

docker run -d -i -t --name=nginx02 --cpus=".5" nginx /bin/bash
Copy the code