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

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

问题描述


  • Windows 10 Professional

  • 在Windows容器中运行的Docker 18.06.1-ce模式

  • 主机系统上4GB的可用内存

  • 使用Hyper-V虚拟机

  • Windows 10 Professional
  • Docker 18.06.1-ce running in Windows container mode
  • 4GB of available memory on host system
  • using Hyper-V virtual machine

当尝试通过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%\Docker\settings.json (例如 C:\Users\olly\AppData\Roaming\Docker ),内存设置在 memoryMiB 属性。

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

以下内容解决了我的环境出现问题:

The following solved the problem on my environement:


  • 退出Docker

  • 修改 settings.json 文件,使用记事本%APPDATA%\Docker\settings.json 在运行命令提示符下( Windows-Key + R

  • 将值 memoryMiB 调整为 1024 2048 之前)

    • 在Docker 19.x及更高版本中,该属性称为 memoryMiB

    • 在Docker版本18.x中,在将该属性称为 VmMemory
    • $ b $之前b
    • quit Docker
    • modify settings.json file using notepad %APPDATA%\Docker\settings.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天全站免登陆