Skip to content

Instantly share code, notes, and snippets.

@tomaslin
Created November 7, 2014 22:41
Show Gist options
  • Save tomaslin/e877b98b353f47167dbe to your computer and use it in GitHub Desktop.
Save tomaslin/e877b98b353f47167dbe to your computer and use it in GitHub Desktop.
Docker calls with Docker Java client
@Grapes(
@Grab(group='com.github.docker-java', module='docker-java', version='0.10.3')
)
import com.github.dockerjava.api.DockerClient
import com.github.dockerjava.core.DockerClientConfig
import com.github.dockerjava.core.DockerClientBuilder
import com.github.dockerjava.api.command.CreateContainerResponse
DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder()
.withVersion("1.14")
.withUri("mydockerhost")
.build()
DockerClient dockerClient = DockerClientBuilder.getInstance(config).build()
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("env").exec()
dockerClient.startContainerCmd(container.getId()).exec()
int exitCode = dockerClient.waitContainerCmd(container.getId()).exec()
InputStream response = dockerClient.logContainerCmd(container.getId()).withStdErr().withStdOut().exec()
response.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment