首页 > 其他分享 >Using Docker Desktop with WSL2

Using Docker Desktop with WSL2

时间:2023-10-15 12:44:05浏览次数:50  
标签:run Windows WSL Desktop Linux Using Docker WSL2

Windows Subsystem for Linux (WSL) 2 is a full Linux kernel built by Microsoft, which lets Linux distributions run without managing virtual machines. With Docker Desktip running on WSL 2, users can leverage Linux workspaces and avoid maintaining both Linux and Windows build scripts. In addition, WSL 2 provides improvements to file system sharing and boot time.

Docker Desktop uses the dynamic memory allocation feature in WSL 2 to improve the resource consumption. This means Docker Desktop only uses the required amount of CPU and memory resources it needs, while allowing CPU and memory-intensive tasks such as building a container, to run much faster.

Additionally, with WSL 2, the time required to start a Docker daemon after a cold start is significantly faster.

Prerequisites

Before you turn on the Docker Desktop WSL 2 feature, ensure you have:

  • At a minimum WSL version 1.1.3.0., but ideally the latest ver
  • Windows 10, version 21H2 or later, or Windows 11, version 21H2 or later. For more information, see System requirements.
  • Installed the WSL 2 feature on Windows. For detailed instructions, refer to the Microsoft documentation.

Tip

For a better experience on WSL, consider enabling the WSL autoMemoryReclaim setting available since WSL 1.3.10 (experimental).

This feature causes the Windows host to better reclaim unused memory inside the WSL virtual machine, thereby resulting in better memory availability to other host applications. This is particularly helpful with Docker Desktop, since otherwise the WSL VM may consume large amounts (GBs) of memory in the Linux kernel's page cache as Docker builds container images, without ever returning that memory to the host when it becomes unused inside the VM.

Trun on Docker Desktop WSL 2

Important

To avoid any potential conflicts with using WSL 2 on Docker Desktop, you must uninstall any previous versions of Docker Engine and CLI installed directly through Linux distributions before installing Docker Desktop.

1. Download and install the latest version of Docker Desktop for Windows.

2. Follow the usual installation instructions to install Docker Desktop. Depending on which version of Windows you are using, Docker Desktop may prompt you turn on WSL 2 during installation. Read the information displayed on the screen and turn on the WSL 2 feature to continue.

3. Start Docker Desktop from the Windows Start menu.

4. Navigate to Settings.

5. From the General tab, select Use WSL 2 based engine.

    if you have installed Docker Desktop on a system that supports WSL 2, this option is turned on by default. 

6. Select Apply & Restart.

Now docker commands work from Windows using the new WSL 2 engine. 

Enabling Docker support in WSL 2 distros

WSL 2 adds support for "Linux distros" to Windows, where each distro behaves like a VM except they all run on top of a single shared Linux kernel.

Docker Desktop does not require any particular Linux distros to be installed. The docker CLI and UI all work fine from Windows without any additional Linux distros. However for the best developer experience, we recommend installing at least one additional distro and enable Docker support: 

1. Ensue 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 the 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

2. When Docker Desktop starts, go to Settings > Resources > WSL Integration.

 The Docker-WSL integration is enabled on the default WSL distribution, which is Ubuntu. To change your default WSL distro, run:

wsl --set-default <distro name>

3. Select Apply & Restart.

Note

Docker Desktop installs two special-purpose internal Linux distros docker-desktop and docker-desktop-data. The first (docker-desktop) is used to run the Docker engine (dockerd) while the second (docker-desktop-data) stores containers and images. Neither can be used for general development.

Reference

Docker Desktop WSL 2 backend on Windows | Docker Docs

标签:run,Windows,WSL,Desktop,Linux,Using,Docker,WSL2
From: https://www.cnblogs.com/fengjq/p/17765202.html

相关文章

  • ubuntu安装docker
    在Ubuntu上安装Docker非常简单。按照以下步骤进行操作:更新系统软件包列表:CopyCodesudoaptupdate安装必要的软件包,以便使用HTTPS源进行下载:CopyCodesudoaptinstallapt-transport-httpsca-certificatescurlsoftware-properties-common添加Docker官方的GPG......
  • docker安装sqlserver2019
    1.拉取镜像dockerpullmcr.microsoft.com/mssql/server:2019-latest2.执行dockerrun命令: dockerrun--namesqlserver-wangmj--hostnamesqlserver-master\-p1434:1433\-e'ACCEPT_EULA=Y'\-e'SA_PASSWORD=sdfasdfasdfsdf?'......
  • docker 迅雷
    从迅雷群晖套件中提取出来用于其他设备的迅雷远程下载服务程序。https://hub.docker.com/r/cnk3x/xunleidockerrun-d--name=xunlei--hostname=mynas--net=host-eXL_WEB_PORT=8321-v/home/cl/docker/xunlei:/xunlei/data-v/home/cl/Downloads:/xunlei/downloads--res......
  • 使用Docker buildx 为 .NET 构建多平台镜像
    .NET团队有一篇博客改进多平台容器支持,详细介绍了.NET7以上的平台可以轻松的使用Dockerbuildx工具构建多平台的镜像。buildx是Docker官方提供的一个构建工具,它可以帮助用户快速、高效地构建Docker镜像,并支持多种平台的构建。使用buildx,用户可以在单个命令中构建多......
  • docker配置阿里云镜像
    1.登录阿里云账号2.进入管理界面,搜索:容器镜像  1.安装/升级Docker客户端推荐安装1.10.0以上版本的Docker客户端,参考文档docker-ce2.配置镜像加速器针对Docker客户端版本大于1.10.0的用户您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器sudo......
  • Docker命令补充
    一、docker删除已停止的容器1.1、根据容器的状态,删除Exited状态的容器先停止容器、再删除镜像中的容器、最后删除none的镜像。执行命令如下:#停止容器dockerstop$(dockerps-a|grep"Exited"|awk'{print$1}')#删除容器dockerrm$(dockerps-a|grep"Exited"......
  • 轻松掌握组件启动之MongoDB:快速入门、Linux安装和Docker配置指南
    引言我们将继续深入研究组件启动专题。在之前的文章中,我们已经详细介绍了Redis的各种配置使用方法,为读者提供了全面的指导。然而,今天我们将转向另一个备受关注的数据库——MongoDB。MongoDB是一种流行的NoSQL数据库,具有强大的灵活性和可扩展性。在这篇文章中,我们将探索MongoDB的......
  • mysql报错:You must reset your password using ALTER USER statement before executin
    新安装mysql后,登录后,执行任何命令都会报错:YoumustresetyourpasswordusingALTERUSERstatementbeforeexecutingthisstatement.【解决办法】MySQL版本5.7.6版本以前用户可以使用如下命令:mysql>SETPASSWORD=PASSWORD('Admin2022!');MySQL版本5.7.6版本开始的用户可以使......
  • docker入门加实战—Docker镜像和Dockerfile语法
    docker入门加实战—Docker镜像和Dockerfile语法镜像镜像就是包含了应用程序、程序运行的系统函数库、运行配置等文件的文件包。构建镜像的过程其实就是把上述文件打包的过程。镜像结构我们要从0部署一个Java应用,大概流程是这样:准备Linux运行环境(java项目并不需要完整的操作......
  • Windows访问Oracle VM VirtualBox虚拟机下Linux docker
    设置网络中的NAT方式下的端口转发  配置主机端口和客体端口,客体端口设置Linuxdocker容器端口,主机端口设置windows访问docker时用到的端口。比如,Linuxdocker容器端口为80,客体端口设置为80,在windows访问时,通过localhost:主机端口,如localhost:80,就能访问。 ......