2021年1月6日 星期三

setup docker on Windows 2019 for linux & Windows docker image

Reference:

Getting Started with Docker on Windows Server 2019

Docker Linux Container running on Windows Server 2019 #Winserv #Docker #Containers

Getting started with Linux Containers on Windows Server 2019

Docker 基本指令操作

Docker Mysql 配置使用(windows server 2019)

Error response from daemon: hcsshim::CreateComputeSystem: The virtual machine could not be started because a required feature is not installed

Error running linux container on windows 2019 server

Run Hyper-V in a Virtual Machine with Nested Virtualization

安裝步驟:

  • 安裝Windows server 2019 (含桌面),把Windows update都裝上
  • 如果Windows 2019安裝在VM,需啟用 nested virtualization
    • nested virtualization
      • 目前只支援 Intel CPU VT-x EPT technology,BIOS 需啟用
      • 實體機和虛擬機都必須 Windows Server 2016/Windows 10 以上
    • 實體機Hyper-V: 用 powershell 執行 Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true
    • 實體機VMware: CPU 勾選 Expose hardware Assisted virtualization to the guest OS
  • 用管理員權限開powershell
  • Install-WindowsFeature -Name Hyper-V,Containers -IncludeAllSubFeature -IncludeManagementTools
  • Install-WindowsFeature -Name Containers
  • Restart-Computer -Force
  • Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
  • Install-Package -Name docker -ProviderName DockerMsftProvider -Force
  • Start-Service docker
  • docker image pull mcr.microsoft.com/windows/servercore:ltsc2019
  • docker image pull mcr.microsoft.com/windows/nanoserver:1809
  • docker image pull mcr.microsoft.com/dotnet/core/aspnet:3.0
  • docker image pull mcr.microsoft.com/dotnet/core/sdk:3.0.100
  • Enable Linux Container Support
# Set LCOW_SUPPORTED Variable to 1 for enabled
[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")

# Enable Experimental Features in Dockerd daemon.conf
$configfile = @"
{
    "experimental": true
}
"@
$configfile | Out-File -FilePath C:\ProgramData\docker\config\daemon.json -Encoding ascii -Force
  • Linux kernel
Invoke-WebRequest -Uri "https://github.com/linuxkit/lcow/releases/download/v4.14.35-v0.3.9/release.zip" -UseBasicParsing -OutFile release.zip
Expand-Archive release.zip -DestinationPath "$Env:ProgramFiles\Linux Containers\."
  • Restart-Computer -Force
  • docker pull mysql
  • docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw --platform linux -d mysql

測試:

  • docker container run -d -p 8080:80 sixeyed/whoami-dotnet:3.0
  • 用Chrome開啟http://localhost:8080可看到網頁
  • swarm mode測試不成功
Docker指令:
  • docker info
  • docker version
  • docker COMMAND --help
  • docker pull [Image 名稱]:[Image 版本]
  • docker images    # 顯示 docker 的 images 清單
  • docker run [options] [Image 名稱]:[Image 版本] [執行指令]
  • docker ps    # 查看正在執行的 containers
  • docker ps -a    # 查看所有的 containers
  • docker stop [Container ID]
  • docker start [Container ID]
  • docker restart [Container ID]
  • docker rm [Container ID]    # 刪除 container
  • docker rmi [Image ID]    # 刪除 image
  • docker swarm init --advertise-addr [IP address]
  • docker swarm leave --force
  • docker service create --publish 8070:80 --replicas 5 [Image 名稱]:[Image 版本]
  • docker service update [options] SERVICE
  • docker service rm SERVICE


Troubleshooting:

Error message:

docker: Error response from daemon: hcsshim::CreateComputeSystem 0e3c581b7316f66fd396f6007f3260ded7d934c5e6d53c9fedba279b9c0044c2:

        The virtual machine could not be started because a required feature is not installed.

Solution:

  • 實體機啟用 nested virtualization
  • Windows server 2019需安裝 Role Hyper-V

沒有留言:

張貼留言