背景
在用docker进行项目编译的时候,出现性能不足的情况,
1 | zhengkaideMacBook-Pro:blog zhengk$ docker stats b9e5ebd23a78 |
通过命令都无法显示性能情况。
不过可见,最大内存限制在1.952GiB。
动态扩容
先找到docker容器的id
1
2
3zhengkaideMacBook-Pro:blog zhengk$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9e5ebd23a78 hub.baidubce.com/paddlepaddle/paddle:latest-dev "/bin/bash" 4 days ago Up 2 days 22/tcp wizardly_meninsky进行扩容
1
2zhengkaideMacBook-Pro:blog zhengk$ docker update -m 3072m b9e5ebd23a78
Error response from daemon: Cannot update container b9e5ebd23a78843361c3f92dbdb7b07dcf01a85087c4c7b14670dc5cc440433c: Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time注:这里有一个错误提示,说要同步扩大memoryswap。
命令修改如下:
1
2zhengkaideMacBook-Pro:blog zhengk$ docker update -m 3072m --memory-swap -1 b9e5ebd23a78
b9e5ebd23a78再次查看
1
2
3zhengkaideMacBook-Pro:blog zhengk$ docker stats b9e5ebd23a78
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
b9e5ebd23a78 wizardly_meninsky 2.65% 1.752GiB / 1.952GiB 89.74% 965MB / 23.1MB 282GB / 7.76GB 85发现没有什么变化,限制还是1.952GiB。
这是由于docker在MacDesktop环境下默认限制了上限为2G。
Advanced settings are:
CPUs: By default, Docker Desktop for Mac is set to use half the number of processors available on the host machine. To increase processing power, set this to a higher number; to decrease, lower the number.
Memory: By default, Docker Desktop for Mac is set to use
2
GB runtime memory, allocated from the total available memory on your Mac. To increase RAM, set this to a higher number; to decrease it, lower the number.Swap: Configure swap file size as needed. The default is 1 GB.
修改Docker Desktop For Mac
重启容器并查看
1
2
3
4
5
6
7
8
9
10
11
12
13zhengkaideMacBook-Pro:blog zhengk$ docker stop b9e5ebd23a78
b9e5ebd23a78
zhengkaideMacBook-Pro:blog zhengk$ docker start b9e5ebd23a78
b9e5ebd23a78
zhengkaideMacBook-Pro:blog zhengk$ docker stats b9e5ebd23a78
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
b9e5ebd23a78 wizardly_meninsky 0.00% 3.102MiB / 3GiB 0.10% 1.16kB / 0B 11.5MB / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
b9e5ebd23a78 wizardly_meninsky 0.00% 3.055MiB / 3GiB 0.10% 1.16kB / 0B 11.5MB / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
b9e5ebd23a78 wizardly_meninsky 0.00% 3.055MiB / 3GiB 0.10% 1.16kB / 0B 11.5MB / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
b9e5ebd23a78 wizardly_meninsky 0.00% 3.055MiB / 3GiB 0.10% 1.16kB / 0B 11.5MB / 0B 1
扩展
对于桌面版的docker,还是要关注一下系统的配置,开始找了好久死活都没办法扩容。
对于常规的扩容,可参考帮助:
1 | zhengkaideMacBook-Pro:blog zhengk$ docker update --help |
使用命令动态修改之后,如果没重启的话
1 | zhengkaideMacBook-Pro:blog zhengk$ docker stats b9e5ebd23a78 |
无法直观的看到有没有生效,所以建议还是重启一次。