11package io .github .intisy .docker ;
22
33import com .github .dockerjava .api .DockerClient ;
4+ import com .github .dockerjava .api .command .InspectContainerResponse ;
45import com .github .dockerjava .api .command .PullImageResultCallback ;
6+ import com .github .dockerjava .api .exception .NotModifiedException ;
57import com .github .dockerjava .api .model .ExposedPort ;
68import com .github .dockerjava .api .model .HostConfig ;
79import com .github .dockerjava .api .model .Ports ;
8- import com .github .dockerjava .api .exception .NotModifiedException ;
9- import com .github .dockerjava .api .command .InspectContainerResponse ;
1010
1111import java .util .concurrent .TimeUnit ;
1212
1313/**
1414 * @author Finn Birich
1515 */
16- public class EmbeddedDockerManager {
17-
16+ public class ContainerTest {
1817 private final DockerProvider dockerProvider ;
1918 private DockerClient dockerClient ;
2019 private String containerId ;
2120
22- public EmbeddedDockerManager () {
23- String os = System .getProperty ("os.name" ).toLowerCase ();
24- if (os .contains ("win" )) {
25- dockerProvider = new WindowsDockerProvider ();
26- } else if (os .contains ("nix" ) || os .contains ("nux" ) || os .contains ("aix" )) {
27- dockerProvider = new LinuxDockerProvider ();
28- } else if (os .contains ("mac" )) {
29- dockerProvider = new MacDockerProvider ();
30- } else {
31- throw new UnsupportedOperationException ("Unsupported operating system: " + os );
32- }
21+ public ContainerTest () {
22+ dockerProvider = DockerProvider .get ();
3323 }
3424
3525 public void initialize () throws Exception {
@@ -99,17 +89,17 @@ public void shutdown() {
9989 }
10090
10191 public static void main (String [] args ) {
102- EmbeddedDockerManager manager = new EmbeddedDockerManager ();
92+ ContainerTest test = new ContainerTest ();
10393 try {
104- manager .initialize ();
105- manager .pullAndRunContainer ("nginx:alpine" , 80 );
94+ test .initialize ();
95+ test .pullAndRunContainer ("nginx:alpine" , 80 );
10696 System .out .println ("Container started successfully. The application will now shut down." );
107- Runtime .getRuntime ().addShutdownHook (new Thread (manager ::shutdown ));
97+ Runtime .getRuntime ().addShutdownHook (new Thread (test ::shutdown ));
10898
10999 } catch (Exception e ) {
110100 System .err .println ("A critical error occurred:" );
111- manager .shutdown ();
101+ test .shutdown ();
112102 throw new RuntimeException (e );
113103 }
114104 }
115- }
105+ }
0 commit comments