Created
November 7, 2014 22:41
-
-
Save tomaslin/e877b98b353f47167dbe to your computer and use it in GitHub Desktop.
Docker calls with Docker Java client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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