Win20H1使用Ubuntu and Docker for wsl2

Win20H1支持使用wsl2 (真实Linux内核) docker for win也因此支持了wsl2 ,使用因此得到体验明显提升;另一方面,子系统在wsl缺失的功能也得到弥补,相当于一台运行在win上的虚拟机,而文件系统是互通的;ubuntu和docker均运行在wsl2上面 ,介绍过程穿插介绍了自己的设置,安装教程网上很多了

看看效果图(终端:windows terminal)

Win20H1使用Ubuntu and Docker for wsl2

使用体验

ubuntu

因为是搭载在hyper上,所以网络模块不会出现wsl的错误,获取到的是虚拟网卡IP,可以访问局域网,公网,但不能通过localhost访问windows,例如配置代理时,需要使用windows真实IP

Win20H1使用Ubuntu and Docker for wsl2

终端代理配置

alias setproxy="export http_proxy=http://192.168.1.6:1080;export https_proxy=http://192.168.1.6:1080"
alias unsetproxy="unset http_proxy;unset https_proxy"

将代码写入.bashrc或.zshrc中 并source一下,前提ss可用且开启了局域网共享

这样安装zsh就没问题了,临时代理只需先执行setproxy变量中的code就好了

Docker

docker可以全局命令行操作,cmd、wsl、ps中都可以

由于Hyper wsl2不再与VM 15.5.5冲突,所以docker也就舒服了....

Win20H1使用Ubuntu and Docker for wsl2

安装

Get started with Docker Desktop

获取安装包,安装即可,不需要安装docker机器配置虚拟机

Win20H1使用Ubuntu and Docker for wsl2

VScode

安装remote-wsl、docker实现完美的linux开发环境

Windows terminal

点开设置,也就是打开settings.json配置文件

将下方一长串复制后覆盖配置文件的所有内容

然后关于配置文件的介绍也都有中文注释,可以自行DIY


//要查看默认设置,请在单击“设置”按钮的同时按住“ alt”。 
//有关这些设置的文档,请参见:https://aka.ms/terminal-documentation

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
    "initialCols" : 103,
    "initialRows" : 28,

    "profiles":
    {
        "defaults":
        {
            //在此处放置要应用到所有配置文件的设置
            "fontFace": "Source Code Pro", //修改默认字体
            "startingDirectory": null
        },
        "list":
        [
            {
                //在此处对powershell.exe配置文件进行更改
                "acrylicOpacity" : 0.9, //修改不透明度
                "cursorShape" : "vintage", //光标样式 默认为bar
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "colorScheme": "OneHalfDark", //配色方案选择
                "commandline": "powershell.exe",
                "hidden": false,
                "useAcrylic" : true //毛玻璃效果开关
            },
            {
                //在此处对cmd.exe配置文件进行更改
                "acrylicOpacity" : 0.80,
                "cursorShape" : "vintage", //光标样式 默认为bar
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "cmd",
                "commandline": "cmd.exe",
                "colorScheme": "Tomorrow Night",
                "hidden": false,
                "useAcrylic" : true
            },
            {
                "acrylicOpacity" : 0.88,
                "cursorShape" : "vintage", //光标样式 默认为bar
                "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
                "hidden": false,
                "name": "Ubuntu-18.04",
                "source": "Windows.Terminal.Wsl",
                "colorScheme": "Ubuntu",
                "useAcrylic" : true
            },

            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure",
                "useAcrylic" : true
            },

            {
              "guid": "{46ca431a-3a87-5fb3-83cd-11ececc031d2}",
              "cursorShape" : "vintage", //光标样式 默认为bar
              "hidden": false,
              "name": "kali-linux",
              "colorScheme": "Tomorrow Night",
              "source": "Windows.Terminal.Wsl",
              "useAcrylic" : true
            }
        ]
    },

    //向此数组添加自定义配色方案
    //更多主题配色方案 https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/windowsterminal
    "schemes": [
        {
            "name": "Tomorrow Night",
            "black": "#000000",
            "red": "#cc6666",
            "green": "#b5bd68",
            "yellow": "#f0c674",
            "blue": "#81a2be",
            "purple": "#b294bb",
            "cyan": "#8abeb7",
            "white": "#ffffff",
            "brightBlack": "#000000",
            "brightRed": "#cc6666",
            "brightGreen": "#b5bd68",
            "brightYellow": "#f0c674",
            "brightBlue": "#81a2be",
            "brightPurple": "#b294bb",
            "brightCyan": "#8abeb7",
            "brightWhite": "#ffffff",
            "background": "#1d1f21",
            "foreground": "#c5c8c6"
          },
          {
            "name": "OneHalfDark",
            "black": "#282c34",
            "red": "#e06c75",
            "green": "#292c32",//#98c379
            "yellow": "#e5c07b",
            "blue": "#61afef",
            "purple": "#c678dd",
            "cyan": "#56b6c2",
            "white": "#dcdfe4",
            "brightBlack": "#282c34",
            "brightRed": "#e06c75",
            "brightGreen": "#98c379",
            "brightYellow": "#e5c07b",
            "brightBlue": "#61afef",
            "brightPurple": "#c678dd",
            "brightCyan": "#56b6c2",
            "brightWhite": "#dcdfe4",
            "background": "#282c34",
            "foreground": "#dcdfe4"
          },
          {
            "name": "Tomorrow",
            "black": "#000000",
            "red": "#c82829",
            "green": "#718c00",
            "yellow": "#eab700",
            "blue": "#4271ae",
            "purple": "#8959a8",
            "cyan": "#3e999f",
            "white": "#ffffff",
            "brightBlack": "#000000",
            "brightRed": "#c82829",
            "brightGreen": "#718c00",
            "brightYellow": "#eab700",
            "brightBlue": "#4271ae",
            "brightPurple": "#8959a8",
            "brightCyan": "#3e999f",
            "brightWhite": "#ffffff",
            "background": "#ffffff",
            "foreground": "#4d4d4c"
          },
          {
            "name": "Ubuntu",
            "black": "#2e3436",
            "red": "#cc0000",
            "green": "#2e1024",//变更 #4e9a06
            "yellow": "#c4a000",
            "blue": "#3465a4",
            "purple": "#75507b",
            "cyan": "#06989a",
            "white": "#d3d7cf",
            "brightBlack": "#555753",
            "brightRed": "#ef2929",
            "brightGreen": "#8ae234",
            "brightYellow": "#fce94f",
            "brightBlue": "#729fcf",
            "brightPurple": "#ad7fa8",
            "brightCyan": "#56b6c2",//#34e2e2
            "brightWhite": "#eeeeec",
            "background": "#300a24",
            "foreground": "#eeeeec"
          },
          {
            "name": "Twilight",
            "black": "#141414",
            "red": "#c06d44",
            "green": "#afb97a",
            "yellow": "#c2a86c",
            "blue": "#44474a",
            "purple": "#b4be7c",
            "cyan": "#778385",
            "white": "#ffffd4",
            "brightBlack": "#262626",
            "brightRed": "#de7c4c",
            "brightGreen": "#ccd88c",
            "brightYellow": "#e2c47e",
            "brightBlue": "#5a5e62",
            "brightPurple": "#d0dc8e",
            "brightCyan": "#8a989b",
            "brightWhite": "#ffffd4",
            "background": "#141414",
            "foreground": "#ffffd4"
          },
          {
            "name": "MaterialDark",
            "black": "#212121",
            "red": "#b7141f",
            "green": "#457b24",
            "yellow": "#f6981e",
            "blue": "#134eb2",
            "purple": "#560088",
            "cyan": "#0e717c",
            "white": "#efefef",
            "brightBlack": "#424242",
            "brightRed": "#e83b3f",
            "brightGreen": "#7aba3a",
            "brightYellow": "#ffea2e",
            "brightBlue": "#54a4f3",
            "brightPurple": "#aa4dbc",
            "brightCyan": "#26bbd1",
            "brightWhite": "#d9d9d9",
            "background": "#232322",
            "foreground": "#e5e5e5"
          },
          {
            "name": "Atom",
            "black": "#000000",
            "red": "#fd5ff1",
            "green": "#87c38a",
            "yellow": "#ffd7b1",
            "blue": "#85befd",
            "purple": "#b9b6fc",
            "cyan": "#85befd",
            "white": "#e0e0e0",
            "brightBlack": "#000000",
            "brightRed": "#fd5ff1",
            "brightGreen": "#94fa36",
            "brightYellow": "#f5ffa8",
            "brightBlue": "#96cbfe",
            "brightPurple": "#b9b6fc",
            "brightCyan": "#85befd",
            "brightWhite": "#e0e0e0",
            "background": "#161719",
            "foreground": "#c5c8c6"
          }

    ],

    //向此数组添加任何键绑定替代。 
    //要取消绑定默认的绑定,请将命令设置为“ unbound”
    "keybindings": [
{ "command" : "newTab", "keys" : ["ctrl+N"] },
	        { "command" : "closeTab", "keys" : ["ctrl+w"] },
	        { "command" : "closePane", "keys" : ["ctrl+w"]},
	        { "command" : "copy", "keys" : ["ctrl+c"]},
	        { "command" : "paste","keys" : ["ctrl+v"]},
	        { "command" : "find","keys" : ["ctrl+f"]},//搜索框
	        { "command" : "splitVertical", "keys": ["alt+-"]},//垂直方向分屏
	        { "command" : "splitHorizontal", "keys": ["alt+="]},//水平方向分屏
	        { "command" : "increaseFontSize", "keys": ["ctrl+]"]},//增大字体
	        { "command" : "decreaseFontSize", "keys": ["ctrl+["]},//减小字体
	        { "command" : "duplicateTab", "keys" : ["ctrl+shift+d"]},
	        { "command" : "newTabProfile0","keys" : ["ctrl+shift+1"]},
	        { "command" : "newTabProfile1","keys" : ["ctrl+shift+2"]},
	        { "command" : "newTabProfile2","keys" : ["ctrl+shift+3"]},
	        { "command" : "newTabProfile3","keys" : ["ctrl+shift+4"]},
	        { "command" : "newTabProfile4", "keys" : ["ctrl+shift+5"]},
	        { "command" : "newTabProfile5","keys" : ["ctrl+shift+6"]},
	        { "command" : "newTabProfile6","keys" : ["ctrl+shift+7"]},
	        { "command" : "newTabProfile7","keys" : ["ctrl+shift+8"]},
	        { "command" : "newTabProfile8","keys" : ["ctrl+shift+9"]},        
	        { "command" : "openNewTabDropdown","keys" : ["ctrl+shift+space"]},
	        { "command" : "openSettings","keys" : ["ctrl+,"]},//打开配置文件
	        { "command" : "nextTab","keys" : ["ctrl+tab"]},//上一个tab
	        { "command" : "prevTab","keys" : ["ctrl+shift+tab"]},//下一个tab
	        { "command" : "scrollDown","keys" : ["ctrl+shift+down" ]},//向下滚动        
	        { "command" : "scrollUp","keys" : ["ctrl+shift+up"]},//向上滚动
	        { "command" : "scrollUpPage","keys" : ["pgup"]},//向上翻页
	        { "command" : "scrollDownPage","keys" : ["pgdn"]},//向下翻页
	        { "command" : "switchToTab0","keys" : ["ctrl+alt+1"]},
	        { "command" : "switchToTab1","keys" : ["ctrl+alt+2"]},
	        { "command" : "switchToTab2","keys" : ["ctrl+alt+3"]},
	        { "command" : "switchToTab3","keys" : ["ctrl+alt+4"]},
	        { "command" : "switchToTab4","keys" : ["ctrl+alt+5"]},
	        { "command" : "switchToTab5","keys" : ["ctrl+alt+6"]},
	        { "command" : "switchToTab6","keys" : ["ctrl+alt+7"]},
	        { "command" : "switchToTab7","keys" : ["ctrl+alt+8"]},
	        { "command" : "switchToTab8","keys" : ["ctrl+alt+9"]}
]
}

Win20H1使用Ubuntu and Docker for wsl2

上一篇:vue+webAPI中json相互转换的点滴记录,用于实现按分值的调查问卷功能


下一篇:C#中break 和 continue 和 return在if语句和for循环中的区别