diff --git a/src/main/java/com/guwan/backend/controller/DockerController.java b/src/main/java/com/guwan/backend/controller/DockerController.java index a357936..5f4ff5b 100644 --- a/src/main/java/com/guwan/backend/controller/DockerController.java +++ b/src/main/java/com/guwan/backend/controller/DockerController.java @@ -1,14 +1,17 @@ package com.guwan.backend.controller; -import com.github.dockerjava.api.model.Container; -import com.github.dockerjava.api.model.Image; +import com.github.dockerjava.api.command.CreateContainerCmd; +import com.github.dockerjava.api.model.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.model.Info; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.List; @@ -52,9 +55,48 @@ public class DockerController { @GetMapping("/listContainers") public List listContainers() { List exec = dockerClient.listContainersCmd().exec(); - + exec.forEach(container -> System.out.println("name = " + Arrays.toString(container.getNames()))); return exec; } + + + @GetMapping("/create") + public void create() throws IOException { + + + + String javaFilePath = "D:\\00_桌面\\demo.java"; // 这里填入 Java 文件路径 + File javaFile = new File(javaFilePath); + + Path localDir = Files.createTempDirectory("docker-java"); + File localJavaFile = new File(localDir.toFile(), "Main.java"); + Files.copy(javaFile.toPath(), localJavaFile.toPath()); + + + + String imageName = "openjdk:8"; // 使用官方 OpenJDK 11 镜像 + + + HostConfig hostConfig = HostConfig.newHostConfig() + .withBinds(new Bind(localDir.toString(), new com.github.dockerjava.api.model.Volume("/java"))); // 绑定挂载 + + + // 启动容器 + String containerId = dockerClient.createContainerCmd(imageName) + .withCmd("bash", "-c", "javac /java/Main.java && java -cp /java Main && tail -f /dev/null") + .withHostConfig(hostConfig) + .withName("java-app-container") + .exec().getId(); + + dockerClient.startContainerCmd(containerId).exec(); + + System.out.println("Container started. Check the output in Docker."); + + } + + + + } diff --git a/src/test/java/com/guwan/backend/Demo.java b/src/test/java/com/guwan/backend/Demo.java index a5548e9..4bc8cdc 100644 --- a/src/test/java/com/guwan/backend/Demo.java +++ b/src/test/java/com/guwan/backend/Demo.java @@ -43,7 +43,7 @@ public class Demo { - String filePath = "D:\\00_桌面\\1.txt"; + String filePath = "D:\\00_桌面\\demo\\张瑞杰.txt"; double[] doubles = readFileToDoubleArray(filePath); @@ -52,6 +52,14 @@ public class Demo { // double[] doubles = {}; // double数组转float数组 +// String feature = "VS2Evcroib3MM4i6Tt/7PBMpRb2dUY49Jx6CPRU00rwIivi8mbdyPEeoaLyyf9a8cVKZPOuHu706Wd89LUgHveUOHbwkxO68leY0vaztmL0m5wm9ZfLYPJ9bZbuxU8m9YEHVvKF9Vz3VU7E73CJuvW+0vjwZj4S7r+GCPZnb1jz0blc9jgIHPcJRD71A+8a72vlxvE/+qLzOG4e87HFyPHDbSL1ff/i8soF1vc4SHb0XM2G9cQTuPA+yq71rZz29Hy4oPami27w8QMY9UYpyvQR4ILz/3m89ZiQPPf1VAr3gpc08SGBquyYDxLyFuJo9//qDO0jzOz2ctX28yrvPvCcVrbzsnSM9EP4Uu2dFJj077hK8K9tCPH6cjjwwzaS8J88CPDJIt724Iis68vTyPDQYOLyeWBY8eCRJPdwnyDxfQDU9zV7HuozxbD2kNFK95zoVPWtFDr0lRYy824ibvXjmeT3IkR+9TcoDOsJ8mj0Vdiu7SDqcvCu4kDw+45k9AcEovANcpD2bHAm9rsRHuklWn7vKu4g83FPCO2su3bsTAEy9gnYeu/BRvbtI3ss9KilavWSD9jzQDjC9b81IPJYbRr0SGBc9KdOEvLm3Q73nsAK9/62CO2VMxbxW+ZK9GgesPQAt9LyCY4S78zQbvTdz5TxUYpS6uDnEuyNSzr02tVe96nBYPT86/D1CWnc9PchtPfs8nj033hq8+cHVPL0abr01cYC9PdjSPFKIhr37iqq7J3lkve9QsL1n8y49F6FqvRPj0byrBcO8G7J/O0kxEr0iUpy9RWX3OvJN8jxvoQy8rkFJvJEv6zzvrUU7tCM4vTEntjynu7e9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RQQpPCzt8LzUUKE83rAbvMqoq7tlJ3M8jVgXO/CiGTwchKY9XrhovZhAgD3Ui5I9ypSyPJwWhTvirQc7tR3gO+qpDz0hITK9kWo6vbHZtL0dDWg9s0Tavey4bD0JYy28ThmmvFHdLr0jcXC83GoDvo1nxru8kTu9DcSRvFByHbzuHei8BZpMvGsx+DwP0Hi91ltCPbqZEjwDNHO8C8v9vFhB8bw/o447UIGFvEKrmz2sFIO8Z0TQvJx0BT30q0k8HulsPIXUEz3xUNu7l/WPPH5bQj1l0am999D3O+A+/DtZrME8BXMLvShSKbyCfYs91V2FvZNCfLt1XI28u0XmvIzDjjz4Sy+9rGAVvXvKKL32UL698WaePGoNGzxjW6Y8NO0rPRgCyzy8kuk7x/ECu8QV5LwwZII9wxoevLp0MT2JGFE76xCNu1lnvTwcM0+9msPLPGgB8jzIlfe8TzWLvPy3b73t5sG8Llo1vaMjD711TTE9l8hoPDkTHT3lqjE8QTo+vMdMSTzfQUK4myOqOuPRur1t9w29z5oBPWHtvzx8LNA90dKbvDYh1Ly3h/a8fIsgPKKwQjnfLQg9+USVOk5OEruDB5s8cnAMPYETHbwtE1c9OAQwO/3XkD3osve8uSddvZRUOr30Pe287xfnPJ9pHD3+Goc949hlvfI9WLyuZvO8a+ihPH/kCD0+Hv28PjKhu7FvPL3+T4Q9iYC5vIbQG71tAAk7+JHcPW+j1DzEYBc8lwq+Pf87jD28wrw9Y7SduhEtVb0="; +// byte[] featureData = Base64.getDecoder().decode(feature); +// +// //把byte数组转成float数组 +// float[] floats = byteArrayToFloatArray(featureData); +// +// System.out.println("floats = " + Arrays.toString(floats)); + float[] floatArray = doubleArrayToFloatArray(doubles);