就在上周,Docker官方的master分支上新增了LCOW(Linux Containers on Windows)[1]功能。启用这项功能,即可在单一的Docker引擎下,同时运行Linux和Windows容器。
可以用Docker命令docker ps,列出所有正在运行的Linux或Windows容器。
在容器和主机之间通过存储卷共享数据。
容器之间可以通过容器网络互相通信。
通过将端口映射到主机,实现本地访问。但目前,它还只是Windows 10 1803版预览体验计划(Windows Insider)的一项功能。
现在,你需要指定--platform来拉取Linux镜像。如果拉取的是一个既有Linux又有Windows的多重架构的镜像,同样需要指定该选项。
docker pull --platform linux alpine
docker run alpine uname -a
接下来我们看一下,如何用一种简单的方式,实现不同平台容器间的数据共享。
cd \
mkdir host
docker run -it -v C:\host:\test alpine sh
uname -a > test/hello-from-linux.txt
docker run -i -v C:\host:C:\test microsoft/nanoserver:1709 cmd
ver > test\hello-from-windows.txt
PS C:\> dir host
Directory: C:\host
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/21/2018 4:32 AM 85 hello-from-linux.txt
-a---- 1/21/2018 4:33 AM 46 hello-from-windows.txt
值得一提的是,使用Docker Compose还可混合编排容器。下面是一个混合编排Linux和Window web服务器的例子。
version: "3.2"
services:
web1:
image: nginx
volumes:
- type: bind
source: C:\host
target: /test
ports:
- 80:80
web2:
image: stefanscherer/hello-dresden:0.0.3-windows-1709
volumes:
- type: bind
source: C:\host
target: C:\test
ports:
- 81:3000
networks:
default:
external:
name: nat
如果你想试着玩一下LCOW,建议使用Windows 10 1709虚拟机。
Enable-WindowsOptionalFeature -Online -FeatureName containers -All -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart
Invoke-WebRequest -OutFile "$env:TEMP\linuxkit-lcow.zip" "https://23-111085629-gh.circle-artifacts.com/0/release.zip"
Expand-Archive -Path "$env:TEMP\linuxkit-lcow.zip" -DestinationPath "$env:ProgramFiles\Linux Containers" -Force
Invoke-WebRequest -OutFile "$env:TEMP\docker-master.zip" "https://master.dockerproject.com/windows/x86_64/docker.zip"
Expand-Archive -Path "$env:TEMP\docker-master.zip" -DestinationPath $env:ProgramFiles -Force
. $env:ProgramFiles\docker\dockerd.exe --register-service --experimental
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$($env:ProgramFiles)\docker", [EnvironmentVariableTarget]::Machine)
如果你的Vagrant安装了Hyper-V或VMware,那就更方便了。只需几个命令,就可轻松搭建本地测试环境。
git clone https://github.com/StefanScherer/docker-windows-box
cd docker-windows-box
cd lcow
vagrant up
未来几个月,随着这些Docker新功能加入到Windows,Windows 10无疑将成为2018年最具吸引力的开发者平台。
https://github.com/moby/moby/pull/34859
https://github.com/linuxkit/lcow/releases
https://twitter.com/stefscherer
原文链接:https://stefanscherer.github.io/sneak-peek-at-lcow/
LCOW —— 单一Docker引擎下可同时运行Linux和Windows容器啦!
原文:https://www.cnblogs.com/bigben0123/p/8884523.html