如何为 Docker 容器提供更多资源

How to Give Docker Containers more resources

我正在使用 docker 创建用于开发 Magento 模块的本地开发环境。 Magento 在大多数操作期间非常慢,我注意到 CPU 每个内核的使用率不会高于 20%(我的机器有 8 个内核)。

是否有任何我可以更改的设置,以便在 CPU 使用方面为 docker 容器提供更多资源?

你还有其他容器吗运行?文档指出:

By default, all containers get the same proportion of CPU cycles. This proportion can be modified by changing the container’s CPU share weighting relative to the weighting of all other running containers.

您可以在 compose 文件中修改容器的资源分配 (link)

使用时可以自定义资源参数docker run

喜欢:

--cpu-shares        CPU shares (relative weight)
--cpu-period        Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota         Limit CPU CFS (Completely Fair Scheduler) quota
--cpuset-cpus       CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems       MEMs in which to allow execution (0-3, 0,1)

我用的是Docker的1.11.1版本,我记不太清了,但也许其中一些参数只能在较新的版本中使用。

See docker run reference -> https://docs.docker.com/engine/reference/run/