A very tiny wrapper around a ProcessBuilder
for running docker commands.
Just that, a very tiny standalone .jar which can be imported into a project to do a very specific thing.
Since we're making good use of JitPack, this is simple.
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.peavers:docker-micro-library:-SNAPSHOT'
}
Click the JitPack build badge for more examples with maven, sbt example.
Wire up the DockerApi
and the DockerContainer
@Configuration
public class DockerConfig {
@Bean
public DockerApi dockerApi() {
return new DockerApiImpl();
}
@Bean
public DockerContainer container() {
return new DockerContainer();
}
}
Load up the DockerContainer
and execute
@Component
public class CreateContainer {
private final DockerContainer container;
private final DockerApi dockerApi;
public CreateContainer(DockerContainer container, DockerApi dockerApi) {
this.container = container;
this.dockerApi = dockerApi;
}
private void create() {
container.setName("Name of the container");
container.setImage("createContainer:latest");
dockerApi.run(container);
}
}