Write-Output $addHosts $module = "video_course" $dockerImage ="docker.beswell.com:5050/loallout/$module" $cmd = "docker pull ${dockerImage}:latest" Invoke-Expression $cmd $cName = "loallout_hr_$module" $cmd = "docker stop $cName" try { Invoke-Expression $cmd } catch { } $cmd = "docker rm $cName" try { Invoke-Expression $cmd } catch { } if ($IsWindows) { $configPath = $PSScriptRoot $consulAddr = "host.docker.internal:8500" $hostsPath = "C:\WINDOWS\system32\drivers\etc\hosts" $timeZone =" " } if ($IsLinux){ $configPath = "/etc/bsw/loallout/$module" $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 " } } } $cmd = "docker run -d -p 50051:58080 -P --name $cName $addHosts -v /etc/video_course:/conf $timeZone -e CONSUL_ADDR=$consulAddr -e DEBUG=TRUE --restart=always ${dockerImage}:latest" Write-Output "exec cmd: $cmd" Invoke-Expression $cmd