param( [switch]$u ) $beginPWD = $PWD Write-Output $addHosts $dockerImage ="docker.beswell.com:5050/sportfitness/base" if ($u) { $cmd = "docker pull ${dockerImage}:latest" Write-Output "更新稳定版" Invoke-Expression $cmd } Set-Location $PSScriptRoot #try { # docker stop bsw_im #} #catch { #} #try { # docker rm bsw_im #} #catch { #} if ($IsWindows) { $configPath = $PSScriptRoot $consulAddr = "host.docker.internal:8500" $hostsPath = "C:\WINDOWS\system32\drivers\etc\hosts" $timeZone =" " } if ($IsLinux){ $configPath = "/etc/bsw/signaldig2" $consulAddr = "172.17.0.1:8500" $hostsPath = "/etc/hosts" $timeZone = " -v /etc/localtime:/etc/localtime " } $hosts = Get-Content $hostsPath | Where-Object { $true -ne [string]::IsNullOrWhiteSpace($_) } $addHosts = "" foreach ($item in $hosts) { if (!($item -match ".*#.*")) { $array = $item.Split("`t", [StringSplitOptions]::RemoveEmptyEntries) $ip = $array[0] $hostArray = $array[1..$array.Length] foreach ($h in $hostArray){ $addHosts = $addHosts + " --add-host ${h}:$ip " } } } docker-compose up -d Set-Location $beginPWD #$cmd = "docker run -d -P --name bsw_im $addHosts $timeZone -e CONSUL_ADDR=$consulAddr --restart=always ${dockerImage}:latest" #Write-Output "exec cmd: $cmd" #Invoke-Expression $cmd