I need a script to reclaim hard disk, remove the currently running container, build and run the new image in docker on windows desktop.
The following code first removes unused images and then gets the image running on the port 5555. I will have to play the string replace tricks using PowerShell. Please check "-replace" part for details.
#prune unused image
docker image prune -f
#remove existing running docker image
$a = docker container ls --filter expose=5555
$a2 = $a | foreach-object {$_ -replace '\s{3,}', ' '} | foreach-object {$_ -replace ' ', "`t"}
$obj = ConvertFrom-Csv -InputObject $a2 -Delimiter "`t"
if ($obj -ne $null)
{
docker rm -f $obj.names
}
else
{
Write-Verbose "cannot find running container image so won't remove"
}
#build flask app and set its version to 1
docker build -t flaskapp:1 .
docker run -d -p 5555:5555 flaskapp:1
#test running instance
sleep -s 4
invoke-restmethod "http://localhost:5555/api/health"
No comments:
Post a Comment