win server 安装docker 需要安装企业版,社区版只支持win10
过程如下:
首先安装oneget PowerShell模块
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
再使用oneget 安装最新版本docker
Install-Package -Name docker -ProviderName DockerMsftProvider
powershell中询问你是否确实要安装来自“DockerDefault”的软件,选择“A”全是。
PS C:\> Install-Module -Name DockerMsftProvider -Repository PSGallery -Force PS C:\> Install-Package -Name docker -ProviderName DockerMsftProvider 程序包来自未标记为“受信任”的程序包源。 是否确实要安装来自“DockerDefault”的软件? [Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): A 警告: A restart is required to start docker service. Please restart your machine. 警告: After the restart please start the docker service. Name Version Source Summary ---- ------- ------ ------- Docker 1.12.2-cs2-ws... DockerDefault Contains the CS Docker Engine for use with Windows ...
如果安装过程中出现网络问题,可以使用迅雷下载完成后放入对应的位置
例如我安装的 19.03.5版本
下载后位置为: C:\Users\ADMINI~1\AppData\Local\Temp\1\DockerMsftProvider\Docker-19-03-5.zip
url地址为:https://dockermsft.azureedge.net/dockercontainer/docker-19-03-5.zip
下载好后运行:
Get-FileHash -Path C:\Users\ADMINI~1\AppData\Local\Temp\1\DockerMsftProvider\Docker-19-03-5.zip -Algorithm SHA256 Install-Package -Name docker -ProviderName DockerMsftProvider -Verbose
安装完成重启计算机
Restart-Computer -Force
在powershell中输入,docker version,显示docker版本
PS C:\Users\Administrator> docker version Client: Version: 1.12.2-cs2-ws-beta API version: 1.25 Go version: go1.7.1 Git commit: 050b611 Built: Tue Oct 11 02:35:40 2016 OS/Arch: windows/amd64 Server: Version: 1.12.2-cs2-ws-beta API version: 1.25 Go version: go1.7.1 Git commit: 050b611 Built: Tue Oct 11 02:35:40 2016 OS/Arch: windows/amd64
使用docker run 部署一个.net core hellworld官方应用程序镜像
docker run microsoft/dotnet-samples:dotnetapp-nanoserver
会看到跟linux部署容器一样的界面
PS C:\Users\Administrator>docker run microsoft/dotnet-samples:dotnetapp-nanoserver Unable to find image 'microsoft/dotnet-samples:dotnetapp-nanoserver' locally dotnetapp-nanoserver: Pulling from microsoft/dotnet-samples 5496abde368a: Downloading [===> ] 14.6 MB/242.6 MB 482ab31872a2: Downloading [=========> ] 19.46 MB/100.5 MB df00079eb06a: Download complete 79730b122a0a: Download complete e2f5db19e1d2: Downloading [===> ] 2.293 MB/32.48 MB c34ebc4d7351: Waiting 8c97c2cd28c1: Waiting 6bd62be70d1c: Waiting 9b45b5fe5811: Waiting
参考文章:
https://msdn.microsoft.com/virtualization/windowscontainers/containers_welcome
在Windows Server 2019上运行Linux容器
开箱即用,Windows上的Docker只运行Windows容器,要在Windows Server上使用Linux容器,需要使用Docker Enterprise Edition Preview,其中包含用于运行Docker Linux容器的完整LinuxKit系统。
卸载当前的Docker CE:
Uninstall-Package -Name docker -ProviderName DockerMSFTProvider
如果你使用在Hyper-V上运行的Linux虚拟机运行Docker容器,则启用嵌套虚拟化:
Get-VM WinContainerHost | Set-VMProcessor -ExposeVirtualizationExtensions $true
然后安装Docker EE的当前预览版本:
Install-Module DockerProvider Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview
启用LinuxKit系统以运行Linux容器:
[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")
更改后重新启动Docker Service:
Restart-Service docker
测试docker image一下:
> docker run -it –rm ubuntu /bin/bash
root@1440a7fef7e0:/# cat /etc/os-release
NAME=”Ubuntu”
VERSION=”18.04.1 LTS (Bionic Beaver)”
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME=”Ubuntu 18.04.1 LTS”
VERSION_ID=”18.04″
HOME_URL=”https://www.ubuntu.com/”
SUPPORT_URL=”https://help.ubuntu.com/”
BUG_REPORT_URL=”https://bugs.launchpad.net/ubuntu/”
PRIVACY_POLICY_URL=”https://www.ubuntu.com/legal/terms-and-policies/privacy-policy”
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
root@1440a7fef7e0:/# exit
exit
要切换回运行的Windows容器,请运行:
[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "$null", "Machine")
至此,在Windows Server 2019上运行Linux容器的内容讲完了。
# win 2016 安装 基于Linux的docker
1、安装之前的步骤,安装docker osType: windows
2、下载docker-machine-Windows-x86_64.exe
https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-Windows-x86_64.exe
3、docker-machine-Windows-x86_64.exe create –engine-registry-mirror=https://XXXXXX(换上你的阿里云专属镜像).mirror.aliyuncs.com -d hyperv –hyperv-virtual-switch “switch” VM8
注意:switch是再hyper-v里配置的虚拟交换机
等着好一会儿。。。
Creating CA: C:\Users\Administrator\.docker\machine\certs\ca.pem
Creating client certificate: C:\Users\Administrator\.docker\machine\certs\cert.pem
Running pre-create checks…
(VM8) Image cache directory does not exist, creating it at C:\Users\Administrator\.docker\machine\cache…
(VM8) No default Boot2Docker ISO found locally, downloading the latest release…
(VM8) Latest release for github.com/boot2docker/boot2docker is v18.09.0
(VM8) Downloading C:\Users\Administrator\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.09.0/boot2docker.iso…
(VM8) 0%….10%….20%….30%….40%….50%….60%….70%….80%….90%….100%
Creating machine…
(VM8) Unable to get the local Boot2Docker ISO version: Did not find prefix “-v” in version string
(VM8) Default Boot2Docker ISO is out-of-date, downloading the latest release…
(VM8) Latest release for github.com/boot2docker/boot2docker is v18.09.0
(VM8) Downloading C:\Users\Administrator\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.09.0/boot2docker.iso…
(VM8) 0%….10%….20%….30%….40%….50%….60%….70%….80%….90%….100%
(VM8) Copying C:\Users\Administrator\.docker\machine\cache\boot2docker.iso to C:\Users\Administrator\.docker\machine\machines\VM8\boot2docker.iso…
(VM8) Creating SSH key…
(VM8) Creating VM…
(VM8) Using switch “switch”
(VM8) Creating VHD
(VM8) Starting VM…
(VM8) Waiting for host to start…
Waiting for machine to be running, this may take a few minutes…
Detecting operating system of created instance…
Waiting for SSH to be available…
Detecting the provisioner…
Provisioning with boot2docker…
Copying certs to the local machine directory…
Copying certs to the remote machine…
Setting Docker configuration on the remote daemon…
This machine has been allocated an IP address, but Docker Machine could not
reach it successfully.
SSH for the machine should still work, but connecting to exposed ports, such as
the Docker daemon port (usually <ip>:2376), may not work properly.
You may need to add the route manually, or use another related workaround.
This could be due to a VPN, proxy, or host file configuration issue.
You also might want to clear any VirtualBox host only interfaces you are not using.
Checking connection to Docker…
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine-Windows-x86_64.exe env VM8
提示我们运行命令:docker-machine-Windows-x86_64.exe env VM8
执行完成,有打印出来几行
SET …
SET…
找最后一句:@FOR /f “tokens=*” %i IN (‘docker-machine-Windows-x86_64.exe env VM8’) DO @%i
执行完以后,执行命令 :docker info。
输入一堆信息,然后找OSType:linux。看看对不对?
然后可以用命令进到创建的虚机里:
docker-machine-Windows-x86_64.exe ssh VM8
查看安装docker: docker info