In [1]:
import scala.sys.process._
Out[1]:
In [2]:
"docker images".!!
Out[2]:
In [8]:
val s1 = "docker images".!!
.split("\n").toList.tail
Out[8]:
In [14]:
val s2 = s1.map(_.split("\\s+").toList)
Out[14]:
In [16]:
val s3 = s2.map(x=> x(0)+":"+x(1) -> x(2))
Out[16]:
In [24]:
def findImagesByName(name: String) = {
val s1 = "docker images".!!
.split("\n").toList.tail
//s1=List("mosaico/abuild 3 3af9 ...."...)
val s2 = s1.map(_.split("\\s+").toList)
//s2=List(List("mosaico/abuild","3","3af9",...)...)
val s3 = s2.map(x=> x(0)+":"+x(1) -> x(2))
//List( "mosaico/abuild:3" -> "3af9",....)
s3.filter(_._1.indexOf(name)!= -1)
// filter with first and extract the second
}
Out[24]:
In [25]:
findImagesByName("alpine")
Out[25]:
In [26]:
val args=Array("alpine", ":latest")
Out[26]:
In [32]:
args.flatMap(findImagesByName(_)).distinct.map(_._1)
Out[32]:
In [ ]: