新聞中心
服務(wù)器 環(huán)境說明
環(huán)境:win10企業(yè)版 + ubuntu 18.04 LTS [WSL]
現(xiàn)在 Docker 有專門的 Win10 專業(yè)版系統(tǒng)的安裝包,需要開啟Hyper-V。
開啟 Hyper-V
安裝Docker for windows
最新版 Docker for windows
下載地址: https://docs.docker.com/v17.09/docker-for-windows/install/
點(diǎn)擊 Get Docker for Windows [Stable],并下載 Windows 的版本:
桌邊也會(huì)出現(xiàn)三個(gè)圖標(biāo),入下圖所示:
我們可以在命令行執(zhí)行 docker version
來查看版本號(hào),docker run hello-world
來載入測(cè)試鏡像測(cè)試。
如果沒啟動(dòng),你可以在 Windows 搜索 Docker 來啟動(dòng):
子系統(tǒng)安裝Docker安裝
沒啥問題
leenhem@DESKTOP-7SREO20:~$ sudo apt-get install docker.io Reading package lists... Done Building dependency tree Reading state information... Done docker.io is already the newest version (18.09.7-0ubuntu1~18.04.4). 0 upgraded, 0 newly installed, 0 to remove and 111 not upgraded.
使用 有問題 [無法正常使用]
官網(wǎng)釋疑【解
leenhem@DESKTOP-7SREO20:~$ docker ps Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker status * Docker is not running leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker start * Starting Docker: docker [ OK ] leenhem@DESKTOP-7SREO20:~$ leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker status * Docker is running leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker status * Docker is not running 你會(huì)發(fā)現(xiàn)這個(gè)Docker怎么都啟動(dòng)不了,那現(xiàn)在怎么辦?一定要先看日志(/var/log/docker.log ) leenhem@DESKTOP-7SREO20:~$ tail /var/log/docker.log -n 100 time=2019-10-22T11:58:25.436968100+08:00 level=info msg=ccResolverWrapper: sending new addresses to cc: [{unix:///var/run/docker/containerd/containerd.sock 0}] module=grpc time=2019-10-22T11:58:25.437359900+08:00 level=info msg=ClientConn switching balancer to \\pick_first\\ module=grpc time=2019-10-22T11:58:25.437703900+08:00 level=info msg=pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, CONNECTING module=grpc time=2019-10-22T11:58:25.438698400+08:00 level=info msg=pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, READY module=grpc time=2019-10-22T11:58:25.559058900+08:00 level=info msg=[graphdriver] using prior storage driver: overlay2 time=2019-10-22T11:58:25.719182400+08:00 level=info msg=Graph migration to content-addressability took 0.00 seconds time=2019-10-22T11:58:25.719593400+08:00 level=warning msg=Your kernel does not support cgroup memory limit time=2019-10-22T11:58:25.719660300+08:00 level=warning msg=Unable to find cpu cgroup in mounts time=2019-10-22T11:58:25.719697200+08:00 level=warning msg=Unable to find blkio cgroup in mounts time=2019-10-22T11:58:25.719732900+08:00 level=warning msg=Unable to find cpuset cgroup in mounts time=2019-10-22T11:58:25.719888000+08:00 level=warning msg=mountpoint for pids not found time=2019-10-22T11:58:25.721991900+08:00 level=info msg=stopping healthcheck following graceful shutdown module=libcontainerd time=2019-10-22T11:58:25.722045300+08:00 level=info msg=stopping event stream following graceful shutdown error=context canceled module=libcontainerd namespace=plugins.moby time=2019-10-22T11:58:25.723869300+08:00 level=info msg=pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, TRANSIENT_FAILURE module=grpc time=2019-10-22T11:58:25.724042800+08:00 level=info msg=pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, CONNECTING module=grpc Error starting daemon: Devices cgroup isn\'t mounted 初步結(jié)論:應(yīng)該WIN10內(nèi)核無法完全模擬Linux的cgroup和aufs組件
官網(wǎng)解釋【解決方案】
[Cross Post] WSL Interoperability with Docker
https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
apt install screenfetch screenfetch 腳本:https://files.cnblogs.com/files/rgqancy/WSL.js,下載后另存為txt
建立中繼
現(xiàn)在安裝Go,我們可以構(gòu)建繼電器。在下面的命令中,請(qǐng)確保使用您的Windows用戶名替換:
go get -d github.com/jstarks/npiperelay GOOS=windows go build -o /mnt/c/Users/Administrator/go/bin/npiperelay.exe github.com/jstarks/npiperelay
我們現(xiàn)在已經(jīng)為Windows構(gòu)建了中繼,但我們希望它可以從WSL內(nèi)部調(diào)用。為此,我們創(chuàng)建一個(gè)符號(hào)鏈接。確保使用您的Windows用戶名替換:
sudo ln -s /mnt/c/Users/Administrator/go/bin/npiperelay.exe /usr/local/bin/npiperelay.exe
我們將使用socat來幫助啟用中繼。安裝socat,這是一種允許兩點(diǎn)間數(shù)據(jù)雙向流動(dòng)的工具(稍后詳細(xì)介紹)。抓住這個(gè)包裹:
sudo apt install socat
最后一步
隨著socat的安裝和可執(zhí)行文件的構(gòu)建,我們只需要將幾件事情串起來。我們將制作一個(gè)shell腳本來激活我們的功能。我們將把它放在用戶的主目錄中。去做這個(gè):
#make the file touch ~/docker-relay #add execution privileges chmod +x ~/docker-relay
打開我們用你最喜歡的文本編輯器創(chuàng)建的文件(比如vim)。將其粘貼到文件docker-relay中:
#!/bin/sh exec socat UNIX-LISTEN:/var/run/docker.sock,fork,group=docker,umask=007 EXEC:npiperelay.exe -ep -s //./pipe/docker_engine,nofork
保存該文件并關(guān)閉它。docker-relay腳本將Docker管道配置為允許docker組訪問。要以普通用戶身份運(yùn)行(不必為每個(gè)docker命令附加\'sudo\'),請(qǐng)將您的WSL用戶添加到docker組。在Ubuntu中:
sudo adduserdocker
測(cè)試一下吧!
打開一個(gè)新的WSL外殼以確保您的組成員身份被重置。在后臺(tái)啟動(dòng)中繼:
sudo ~/docker-relay &
現(xiàn)在運(yùn)行docker命令來測(cè)試水域。你應(yīng)該被相同的輸出迎接,就像你從Windows運(yùn)行命令一樣(并且注意你不需要在命令前加\'sudo\'!)
注意
要提前啟動(dòng)docker for windows
原理圖使Docker客戶端在WSL下運(yùn)行以與Docker for Windows通信存在一個(gè)基本問題:WSL客戶端通過unix套接字理解IPC,而Docker for Windows通過命名管道理解IPC。這就是socat和npiperelay.exe發(fā)揮作用的地方–這是這兩種不相交IPC形式之間的中介。Socat理解如何通過unix套接字進(jìn)行通信,npiperelay理解如何通過命名管道進(jìn)行通信。Socat和npiperelay都了解如何通過stdio進(jìn)行通信,因此它們可以彼此通信。
總結(jié)
以上所述是小編給大家介紹的win10子系統(tǒng)ubuntu(WSL) 安裝Docker的教程,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
本文名稱:win10子系統(tǒng)ubuntu(WSL)安裝Docker的教程(圖文詳解)
標(biāo)題URL:http://fisionsoft.com.cn/article/cghpjh.html