如何减少 Windows 上 Docker Linux 容器的默认 VM 内存 [英] How to reduce default VM memory for Docker Linux containers on Windows

查看:25
本文介绍了如何减少 Windows 上 Docker Linux 容器的默认 VM 内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • Windows 10 专业版
  • Docker 18.06.1-ce 在 Windows 容器模式下运行
  • 主机系统上有 4GB 可用内存
  • 使用 Hyper-V 虚拟机

当尝试通过 Docker 的任务栏项目切换到 Linux 容器"时,该过程会在几秒钟后失败,并显示有关内存不足,无法启动 Docker"的错误.

When trying to "switch to Linux containers" via Docker's taskbar item the process fails after a couple of seconds showing an error about "Not enough memory to start Docker".

由于主机系统没有那么多内存,我想减少全局 Docker 机器允许使用的最大内存量(我认为 2 GB 是这里的默认值).因此,我想将其减少到 1 GB.

Since the host system does not have that much memory, I'd like to reduce the maximum amount of memory the global Docker machine is allowed to use (I think 2 GB is the default here). Thus, I'd like to reduce that to just 1 GB.

当 Docker 在 Windows 容器模式下运行时,Docker 的设置中没有高级"部分可以轻松减少内存分配.

When having Docker running in Windows container mode, there is no "advanced" section in Docker's settings that would allow to reduct that memory assignment easily.

我能够使用 Windows 的 Hyper-V 管理器找到MobyLinuxVM".但是,在那里调整内存设置时,每次启动 Docker 并尝试再次切换到 Linux 容器模式时都会覆盖它.

I was able to find the "MobyLinuxVM" using Windows' Hyper-V manager. However, when adjusting memory settings there, it is overwritten each time I start Docker and try again switching to Linux container mode.

是否有其他方法可以在不使用用户界面的情况下定义 Docker 的最大内存量(由于 Windows 容器模式中缺少高级"部分,在这种情况下无法使用 - 在能够切换到之前)Linux 容器)?

Is there a different way to define the maximum amount of memory for Docker without using the user interface (which won't work in this scenario due to the missing "advanced" section in Windows container mode - before being able to switch to Linux containers)?

推荐答案

查了一下发现Docker的用户界面设置保存在%APPDATA%Dockersettings.json中(egC:UsersollyAppDataRoamingDocker),内存设置在memoryMiB属性中定义.

After some searching I found out that settings of Docker's user interface are stored in %APPDATA%Dockersettings.json (e.g. C:UsersollyAppDataRoamingDocker), memory settings are defined in memoryMiB property.

以下解决了我的环境问题:

The following solved the problem on my environement:

  • 退出 Docker
  • 在运行命令提示符下使用 notepad %APPDATA%Dockersettings.json 修改 settings.json 文件(Windows-Key + R)
  • memoryMiB的值调整为1024(之前一直是2048)
    • 在 Docker 版本 19.x 及更高版本中,该属性称为 memoryMiB
    • 在 Docker 版本 18.x 及之前的属性称为 VmMemory
    • quit Docker
    • modify settings.json file using notepad %APPDATA%Dockersettings.json in the run command prompt (Windows-Key + R)
    • adjust value memoryMiB to 1024 (has been 2048 before)
      • in Docker versions 19.x and later the property is called memoryMiB
      • in Docker versions 18.x and before the property was called VmMemory

      这篇关于如何减少 Windows 上 Docker Linux 容器的默认 VM 内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆