zoukankan      html  css  js  c++  java
  • docker中 WSL 配置 修改

    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.

    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
    kernel string The Microsoft built kernel provided inbox An absolute Windows path to a custom Linux kernel.
    memory size 50% of total memory on Windows or 8GB, whichever is less; on builds before 20175: 80% of your total memory on Windows How much memory to assign to the WSL 2 VM.
    processors number The same number of processors on Windows How many processors to assign to the WSL 2 VM.
    localhostForwarding boolean true Boolean specifying if ports bound to wildcard or localhost in the WSL 2 VM should be connectable from the host via localhost:port.
    kernelCommandLine string Blank Additional kernel command line arguments.
    swap size 25% of memory size on Windows rounded up to the nearest GB How 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.
    swapFile string %USERPROFILE%\AppData\Local\Temp\swap.vhdx An absolute Windows path to the swap virtual hard disk.
    pageReporting boolean true Default true setting enables Windows to reclaim unused memory allocated to WSL 2 virtual machine.
    guiApplications boolean* true Boolean to turn on or off support for GUI applications (WSLg) in WSL. Only available for Windows 11.
    debugConsole boolean* false Boolean 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.
    nestedVirtualization boolean* true Boolean to turn on or off nested virtualization, enabling other nested VMs to run inside WSL 2. Only available for Windows 11.
    vmIdleTimeout number* 60000 The 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 重启

    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
       
       
       
       
  • 相关阅读:
    vue插件编写与开发
    http状态码解读
    JavaScript 在HTML中的加载顺序
    vue props的理解
    vue项目中使用scss
    [LeetCode] 57. 插入区间
    [LeetCode] 55. 跳跃游戏
    [LeetCode] 56. 合并区间
    [LeetCode] 54. 螺旋矩阵
    [LeetCode] 53. 最大子序和
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/15739895.html
Copyright © 2011-2022 走看看