wsl中使用原生docker


之前介紹過windows中安裝docker,但是它需要用到hyper-v。hyper-v與vm不兼容非常之不方便。不過發現windows有wsl(linux子系統)遂試驗,結果非常nice功能一應俱全docker完美兼容,與大家分享一下安裝過程。

開啟win10的linux子系統功能

  • 推薦win10升級到最新版本

打開powershell執行命令
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
或者在控制面板中的程序中啟用適用於linux的winodws子系統(直譯?),然后重啟電腦
這時可以去microsoft store中選擇linux發行版,我用的是ubuntu18.04建議大家與我一致。安裝完后打開還需要下載一些文件,大家只需要坐與放寬即可

cmd更換配色

在下載文件時也別閑着,windowns自帶的cmd配色難看至極,一會使用vim的時候保你字都看不清。

  • 去github下載colortool 地址 https://github.com/Microsoft/console
  • 使用管理員打開cmd進入解壓后的文件夾
  • 執行命令 colortool.exe d OneHalfLight(還有其他配色方案,在schemes下)
  • 窗口標題欄右鍵默認值保存,屬性保存

切換root賬戶

一頓操作下來ubuntu也該o98k了,開始設置用戶密碼,然后我們需要使用root賬戶

  • 管理員模式打開ubuntu18.04
  • sudo passwd 輸入密碼與root密碼
  • su root 輸入密碼

但是這時每次打開ubuntu的時候還是普通用戶,我們可以使用命令設置默認用戶
ubuntu1804 config --default-user root

安裝docker

linux子系統已經收工,下面安裝docker。我們可以直接根據docker文檔中提供的ubuntu安裝docker的方法進行操作 ps:使用管理員打開ubuntu1804

因為都知道的網絡原因安裝時可能會timeout等其他情況,我們可以使用國內鏡像 https://mirrors.tuna.tsinghua.edu.cn/ 清華大學開源軟件鏡像站替換下面的鏈接
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/

  • sudo apt-get remove docker docker-engine docker.io
  • sudo apt-get update
  • sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
  • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
  • sudo apt-get update
  • sudo apt-get install docker-ce

一頓操作已經安裝結束,使用 sudo service docker start 開啟docker守護進程
使用 docker version 查看版本

The end

這時開發時就很方便了,也不用擔心hyper-v與vm不兼容的問題。例如在vs code中我們可以很容器的在終端中進行子系統進行各種操作,例如在vs code使用終端進入linux子系統執行各種操作(linux與windows文件共享)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM