CI ZIO2 | CI ZIO1 | Latest release |
---|---|---|
High-level zio interface to docker-java
zio-docker is currently available for Scala 2.13 and 3.1.1-RC1 both for ZIO 1.x and 2.x
- Add zio-docker
For ZIO 2.x (current for ZIO 2.0.0-M6-2)
"st.alzo" %% "zio-docker" % "2.0.1-M1"
For ZIO 1.x
"st.alzo" %% "zio-docker" % "1.0.1"
- Choose docker-java transport from official documentation and add this transport dependency to your project:
For example apache http transport:
"com.github.docker-java" % "docker-java-transport-httpclient5" % dockerJavaVersion
For example with apache httpclient transport
import com.github.dockerjava.api.DockerClient
import com.github.dockerjava.core.{DefaultDockerClientConfig, DockerClientImpl}
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient
import st.alzo.zdocker.{ZDocker, ZDockerLive}
import zio.*
def makeClient(): TaskManaged[ZDocker] = {
ZDocker.fromDockerHttpClient(
DefaultDockerClientConfig.createDefaultConfigBuilder().build()
)(config => Task {
new ApacheDockerHttpClient.Builder()
.connectionTimeout(2.seconds)
.responseTimeout(5.seconds)
.dockerHost(config.getDockerHost)
.build()
})
}
import zio.*
import st.alzo.zdocker.*
import zio.Runtime.default as rt
def helloWorld(): Task[Unit] =
ImageName("hello-world").flatMap { img =>
ZDocker.startManagedContainer(img).use { containerId =>
ZDocker.collectLogs(containerId)
.map(_.value)
.tap(s => ZIO.debug(s))
.runDrain
}
}.provideSome(makeClient().toLayer)
rt.unsafeRun(helloWorld())