docker中 WSL 配置 修改

摘要:
资源资源选项卡允许配置CPU、内存、磁盘、代理、网络和其他资源。不同的设置可用于配置,具体取决于您使用的是Linuxcontainer、SL2模式、Linuxc

docker中 WSL 配置 修改第1张

Resources

The Resources tab allows you to configure CPU, memory, disk, proxies, network, and other resources. Different settings are available for configuration depending on whether you are using Linux containers in WSL 2 mode, Linux containers in Hyper-V mode, or Windows containers.

Advanced

Note

The Advanced tab is only available in Hyper-V mode, because Windows manages the resources in WSL 2 mode and Windows container mode. In WSL 2 mode, you can configure limits on the memory, CPU, and swap size allocated to the WSL 2 utility VM.

Use the Advanced tab to limit resources available to Docker.

  • CPUs: By default, Docker Desktop is set to use half the number of processors available on the host machine. To increase the processing power, set this to a higher number. To decrease the processing power, set this to a lower number.

  • Memory: By default, Docker Desktop is set to use 2 GB runtime memory, allocated from the total available memory on your machine. To increase the RAM, set this to a higher number. To decrease the RAM, lower the number.

  • Swap: Configure swap file size as needed. The default is 1 GB.

  • Disk image size: Specify the size of the disk image.

  • Disk image location: Specify the location of the Linux volume where containers and images are stored.

You can also move the disk image to a different location. If you attempt to move a disk image to a location that already has one, you get a prompt asking if you want to use the existing image or replace it.

WSL Integration

In WSL 2 mode, you can configure which WSL 2 distributions will have the Docker WSL integration.

By default, the integration will be enabled on your default WSL distribution. To change your default WSL distro, run wsl --set-default <distro name>. (For example, to set Ubuntu as your default WSL distro, run wsl --set-default ubuntu).

You can also select any additional distributions you would like to enable the WSL 2 integration on.

For more details on configuring Docker Desktop to use WSL 2, see Docker Desktop WSL 2 backend.

https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configure-global-options-with-wslconfig

.wslconfig

  • Stored in your %UserProfile% directory.
  • Used to configure settings globally across all installed Linux distributions running as the WSL 2 version.
  • Can be used only for distributions run by WSL 2. Distributions running as WSL 1 will not be affected by this configuration as they are not running as a virtual machine.
  • To get to your %UserProfile% directory, in PowerShell, use cd ~ to access your home directory (which is typically your user profile, C:\Users\<UserName>) or you can open Windows File Explorer and enter %UserProfile% in the address bar. The directory path should look something like: C:\Users\<UserName>\.wslconfig.

WSL will detect the existence of these files, read the contents, and automatically apply the configuration settings every time you launch WSL. If the file is missing or malformed (improper markup formatting), WSL will continue to launch as normal without the configuration settings applied.

Check which version of WSL you are running.

 Note

Adjusting per-distribution settings with the wsl.conf file is only available in Windows Build 17093 and later.

docker中 WSL 配置 修改第2张

Configuration setting for .wslconfig

The .wslconfig file configures settings globally for all Linux distributions running with WSL 2. (For per-distribution configuration see wsl.conf).

See .wslconfig for info on where to store the .wslconfig file.

 Note

Global configuration options with .wslconfig is only available for distributions running as WSL 2 in Windows Build 19041 and later. Keep in mind you may need to run wsl --shutdown to shut down the WSL 2 VM and then restart your WSL instance for these changes to take affect.

This file can contain the following options that affect the VM that powers any WSL 2 distribution:

Section label: [wsl2]

TABLE 7
keyvaluedefaultnotes
kernelstringThe Microsoft built kernel provided inboxAn absolute Windows path to a custom Linux kernel.
memorysize50% of total memory on Windows or 8GB, whichever is less; on builds before 20175: 80% of your total memory on WindowsHow much memory to assign to the WSL 2 VM.
processorsnumberThe same number of processors on WindowsHow many processors to assign to the WSL 2 VM.
localhostForwardingbooleantrueBoolean specifying if ports bound to wildcard or localhost in the WSL 2 VM should be connectable from the host via localhost:port.
kernelCommandLinestringBlankAdditional kernel command line arguments.
swapsize25% of memory size on Windows rounded up to the nearest GBHow much swap space to add to the WSL 2 VM, 0 for no swap file. Swap storage is disk-based RAM used when memory demand exceeds limit on hardware device.
swapFilestring%USERPROFILE%\AppData\Local\Temp\swap.vhdxAn absolute Windows path to the swap virtual hard disk.
pageReportingbooleantrueDefault true setting enables Windows to reclaim unused memory allocated to WSL 2 virtual machine.
guiApplicationsboolean*trueBoolean to turn on or off support for GUI applications (WSLg) in WSL. Only available for Windows 11.
debugConsoleboolean*falseBoolean to turn on an output console Window that shows the contents of dmesg upon start of a WSL 2 distro instance. Only available for Windows 11.
nestedVirtualizationboolean*trueBoolean to turn on or off nested virtualization, enabling other nested VMs to run inside WSL 2. Only available for Windows 11.
vmIdleTimeoutnumber*60000The number of milliseconds that a VM is idle, before it is shut down. Only available for Windows 11.

Entries with the path value must be Windows paths with escaped backslashes, e.g: C:\\Temp\\myCustomKernel

Entries with the size value must be a size followed by a unit, for example 8GB or 512MB.

Entries with an * after the value type are only available on Windows 11.

Example .wslconfig file

The .wslconfig sample file below demonstrates some of the configuration options available. In this example, the file path is C:\Users\<UserName>\.wslconfig.

# Settings apply across all Linux distros running on WSL 2
[wsl2]

# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=4GB 

# Sets the VM to use two virtual processors
processors=2

# Specify a custom Linux kernel to use with your installed distros. The default kernel used can be found at https://github.com/microsoft/WSL2-Linux-Kernel
kernel=C:\\temp\\myCustomKernel

# Sets additional kernel parameters, in this case enabling older Linux base images such as Centos 6
kernelCommandLine = vsyscall=emulate

# Sets amount of swap storage space to 8GB, default is 25% of available RAM
swap=8GB

# Sets swapfile path location, default is %USERPROFILE%\AppData\Local\Temp\swap.vhdx
swapfile=C:\\temp\\wsl-swap.vhdx

# Disable page reporting so WSL retains all allocated memory claimed from Windows and releases none back when free
pageReporting=false

# Turn off default connection to bind WSL 2 localhost to Windows localhost
localhostforwarding=true

# Disables nested virtualization
nestedVirtualization=false

# Turns on output console showing contents of dmesg when opening a WSL 2 distro for debugging
debugConsole=true

  

PS C:\Users\[username]> wsl --list --running
适用于 Linux 的 Windows 子系统分发版:
Debian (默认)
docker-desktop-data
docker-desktop
PS C:\Users\[username]> wsl --shutdown
PS C:\Users\[username]> wsl --list --v
  NAME                   STATE           VERSION
* Debian                 Running         2
  docker-desktop-data    Stopped         2
  docker-desktop         Running         2
PS C:\Users\[username]> wsl --list --v
  NAME                   STATE           VERSION
* Debian                 Stopped         2
  docker-desktop-data    Stopped         2
  docker-desktop         Stopped         2
PS C:\Users\[username]>

  

docker中 WSL 配置 修改第3张

docker 重启

PS C:\Users\【username】> wsl --list --v
  NAME                   STATE           VERSION
* Debian                 Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2

  

 https://docs.docker.com/desktop/windows/wsl/

Install

Ensure you have completed the steps described in the Prerequisites section before installing the Docker Desktop Stable 2.3.0.2 release.

  1. Follow the usual installation instructions to install Docker Desktop. If you are running a supported system, Docker Desktop prompts you to enable WSL 2 during installation. Read the information displayed on the screen and enable WSL 2 to continue.
  2. Start Docker Desktop from the Windows Start menu.
  3. From the Docker menu, select Settings > General.

    Enable WSL 2

  4. Select the Use WSL 2 based engine check box.

    If you have installed Docker Desktop on a system that supports WSL 2, this option will be enabled by default.

  5. Click Apply & Restart.
  6. Ensure the distribution runs in WSL 2 mode. WSL can run distributions in both v1 or v2 mode.

    To check the WSL mode, run:

    wsl.exe -l -v

    To upgrade your existing Linux distro to v2, run:

    wsl.exe --set-version (distro name) 2

    To set v2 as the default version for future installations, run:

    wsl.exe --set-default-version 2

  7. When Docker Desktop restarts, go to Settings > Resources > WSL Integration.

    The Docker-WSL integration will be enabled on your default WSL distribution. To change your default WSL distro, run wsl --set-default <distro name>.

    For example, to set Ubuntu as your default WSL distro, run wsl --set-default ubuntu.

    Optionally, select any additional distributions you would like to enable the Docker-WSL integration on.

    Note

    The Docker-WSL integration components running in your distro depend on glibc. This can cause issues when running musl-based distros such as Alpine Linux. Alpine users can use the alpine-pkg-glibc package to deploy glibc alongside musl to run the integration.

    WSL 2 Choose Linux distro

  8. Click Apply & Restart.
How can I change the location of docker images when using Docker Desktop on WSL2 with Windows 10 Home?

I've just upgraded to Windows 10 Home May 2020, activated WSL2, and installed Docker Desktop.

WSL2 must be installed in my system disk, which is a small SSD. I don't want to fill it with docker images. How do I change the docker images path? I'd like to use a path in my big Windows filesystem.

The image location is somewhat confusing. I believe it is in /mnt/wsl/docker-desktop-data/.

How do I change the directory of docker images inside WSL2? May I change docker configuration to select a path inside /mnt/d, or mount a path from /mnt/d over docker data dirs?

The WSL 2 docker-desktop-data vm disk image would normally reside in: %USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx

Follow the following to relocate it to other drive/directory, with all existing docker data preserved (tested against Docker Desktop 2.3.0.4 (46911), and continued to work after updating the 3.1.0 (51484)):

First, shut down your docker desktop by right click on the Docker Desktop icon and select Quit Docker Desktop

Then, open your command prompt:

wsl --list -v

You should be able to see, make sure the STATE for both is Stopped.(wsl --shutdown)

  NAME                   STATE           VERSION
* docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2

Export docker-desktop-data into a file

wsl --export docker-desktop-data "D:\Docker\wsl\data\docker-desktop-data.tar"

Unregister docker-desktop-data from wsl, note that after this, your ext4.vhdx file would automatically be removed (so back it up first if you have important existing image/container):

wsl --unregister docker-desktop-data

Import the docker-desktop-data back to wsl, but now the ext4.vhdx would reside in different drive/directory:

wsl --import docker-desktop-data "D:\Docker\wsl\data" "D:\Docker\wsl\data\docker-desktop-data.tar" --version 2

Start the Docker Desktop again and it should work

You may delete the D:\Docker\wsl\data\docker-desktop-data.tar file (NOT the ext4.vhdx file) if everything looks good for you after verifying

20
Perfect! I wanted to use my HDD instead of SSD for docker images. This was what I was looking for.  Sep 14 '20 at 6:56 
  • 8
    Clear and concise  Sep 23 '20 at 9:27
  •  
    Perfect. The only add-on I can add to this thread, is that I had just purged my cache, and I didn't had this docker-desktop-data present on listing, so I had to start Docker again and quit it in order to create the docker-desktop-data WSL distro again.  Oct 5 '20 at 4:43
  • 8
    Note that you will also need to shutdown wsl before exporting (I got a TimeoutException without that) : wsl --shutdown Oct 19 '20 at 8:24
  • 5
    I suffered from low disk space for so long ... Thank you a lot !  Nov 9 '20 at 15:58
     
     
     
     

免责声明:文章转载自《docker中 WSL 配置 修改》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇VS2015调用matlab Plot函数MacOS 10.15.x 最新安装 Cocoapods 教程及问题解决------实战下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Docker Redis

link - https://store.docker.com/images/redis?tab=description start a redis instance $ docker run --name some-redis -d redis This image includes EXPOSE 6379 (the redis port), so s...

Redis 高可用之哨兵模式

参考 : https://mp.weixin.qq.com/s/Z-PyNgiqYrm0ZYg0r6MVeQ  这篇文章有两个问题 1.虽然运行了3个sentinel容器,实际上只有一个sentinel运行 具体可以留意输出的最后一行 2.外部调试连接redis 获取到的monster地址是docker 的虚拟ip(172.17.0.2:6379)地址,...

(五) Docker 安装 Nginx

参考并感谢 官方文档 https://hub.docker.com/_/nginx 下载nginx镜像(不带tag标签则表示下载latest版本) docker pull nginx 启动 nginxTmp 容器,目的是为了拷贝配置文件 docker run -d -p 80:80 --name nxtmp nginx:latest 登录...

自建Git服务器

最近有线上朋友私信问我怎么搭建个人博客,也有咨询我个人项目的代码是如何保管的,还有一个朋友问我买了服务器玩了一段时间,等新鲜感过了就不知道做什么了。 关于这些问题并没有一个标准答案,每个人都有自己的使用习惯,找到适合你的才是最好的。关于博客搭建及使用的工具或服务在我博客的关于页里已经写的比较详细了,如果有人想看具体步骤我可以专门写一篇详细的教程,本篇先来讲...

docker --- (入门必读)

容器 容器就是一个视图隔离、资源可限制、独立文件系统的进程集合。所谓“视图隔离”就是能够看到部分进程以及具有独立的主机名等;控制资源使用率则是可以对于内存大小以及 CPU 使用个数等进行限制。容器就是一个进程集合,它将系统的其他资源隔离开来,具有自己独立的资源视图。 docker简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及...

Docker daemon socket权限不足

一、概述 普通用户执行命令:docker ps报错,具体信息如下: docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdock...