docker 前言
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
docker-compose
Compose 是用于定义和运行多容器 Docker 应用程序的工具。 使用 Compose,您可以使用 YAML 文件来配置应用程序的服务。 然后,使用单个命令创建并启动所有服务 从您的配置中。
docker 参考
docker | docker-compose | wls | powershell |
download | download | 参考 | 参考 |
安装 docker,docker_compose
-
创建安装自动化脚本
- 实现在线安装docker,docker_compose,安装hayper-v,环境变量,系统服务,防火墙配置,企业微信机器人通,,开机自启动Hyper-v,安装完成需要重启系统哦因为Hyper-v的原因脚本执行完成会自动重启Restart-Computer,有业务运行把脚本内的Restart-Computer去除。
-
Start-Service Docker #启动docker,默认开机自启动
-
docker pull mcr.microsoft.com/windows/servercore:ltsc2019 # 下载docker images
-
docker pull mcr.microsoft.com/dotnet/framework/sdk:3.5-windowsservercore-ltsc2019 #容器项目需要.net的支持
-
$webhook = 企业微信机器人地址
-
C:\Program Files\docker #安装目录位置
-
C:\ProgramData\docker #数据缓存位置,此处是docker 启动后生成的目录
-
以下脚本实现在Windows Server 2019
-
需要将主机,PC,服务器Bios或者UEFI下开启CPU虚拟化技术
powershell-install-docker.ps1
<# Powershell Install docker
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+ _____ _____ _ _ _ +
+ | __ \ / ____| | | | |+
+ | |__) |____ _____ _ _| (___ | |__ ___| | |+
+ | ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | | | (_) \ V V / __/ | ____) | | | | __/ | |+
+ |_| \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++
# Powershell Install docker
# .\powershell-install-docker.ps1
#>
$drive="c:\"
$docker_url="https://download.docker.com/win/static/stable/x86_64/"
$docker_zip="docker-23.0.3.zip"
$docker_site="C:\Program Files\"
$docker_compose_url="https://github.com/docker/compose/releases/download/v2.17.2/"
$docker_compose_exe="docker-compose-windows-x86_64.exe"
Write-Host "install Hyper-V & Containers" -ForegroundColor Green
Install-WindowsFeature -Name Hyper-V,Containers -IncludeManagementTools -Restart:$false
Write-Host "check Hyper-V & Containers " -ForegroundColor Green
Get-WindowsFeature *Hyper-V*,*Container*
Write-Host "Set the system to start the Hypervisor" -ForegroundColor Green
bcdedit /set hypervisorlaunchtype auto
Write-Host "Enable the Windows subsystem for Linux" -ForegroundColor Green
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -all -NoRestart
Write-Host "Enable WSL2" -ForegroundColor Green
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -all -NoRestart
Write-Host "download docker" -ForegroundColor Green
wget -Uri $docker_url$docker_zip -UseBasicParsing -OutFile $drive$docker_zip
Write-Host "download docker" -ForegroundColor Green
wget -Uri $docker_compose_url$docker_compose_exe -UseBasicParsing -OutFile $drive$docker_compose_exe
Write-Host "decompression docker" -ForegroundColor Green
Expand-Archive -Path $drive\$docker_zip -DestinationPath $docker_site
Write-Host "Rename docker-compoer" -ForegroundColor Green
Rename-Item $drive$docker_compose_exe "docker-compose.exe"
Write-Host "Move docker-compoer up docker" -ForegroundColor Green
Move-Item $drive\docker-compose.exe $docker_site\docker
Write-Host "Create docker environment variables" -ForegroundColor Green
$env:path += ";C:\Program Files\docker"
setx PATH $env:path /M
Write-Host "Create a Docker system service" -ForegroundColor Green
New-Service -Name Docker -BinaryPathName "C:\Program Files\docker\dockerd.exe --run-service --experimental=true" -DisplayName "Docker Engine" -Description "Docker Engine - Enterprise Edition"
Write-Host "docker version check" -ForegroundColor Green
docker --version
Write-Host "docker version check" -ForegroundColor Green
docker-compose.exe --version
Write-Host "Add Docker service to firewall allowed list" -ForegroundColor Green
New-NetFirewallRule -DisplayName "Docker engine" -Direction Inbound -Protocol TCP -LocalPort 2376 -Action Allow
Write-Host "delete docker software package" -ForegroundColor Green
Remove-Item $drive$docker_zip -recurse -force -verbose
#Enterprise wechat robot address
$webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXX"
#Obtain the Windows host system version
$Win_version = Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption
$Win_version_Names = echo $Win_version
#docker-compose version
$docker_compose_version = docker-compose.exe -v
#docker version
$docker_version = (Get-Item "C:\Program Files\docker\docker.exe").VersionInfo.FileVersion
$content = Write-Output ""Win_version: $Win_version_Names" `n "docker_compose_version: $docker_compose_version" `n "docker_version: $docker_version""
$body = "{
`"msgtype`":`"text`",
`"text`":{
`"content`":`"$content`",
`"mentioned_list`":[`"jason`"]
}
}"
Write-Host "The variable value obtained is transferred to the enterprise wechat robot" -ForegroundColor Green
Invoke-RestMethod $webhook -ContentType "application/json;charset=utf-8" -Method Post -Body $body
Write-Host "reboot system" -ForegroundColor Green
Restart-Computer
执行安装,下载慢的化,手动下载下来在进行部署,注释wget部分
.\powershell-install-docker.ps1