///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS com.google.cloud.tools:jib-core:0.20.0 import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import com.google.cloud.tools.jib.api.Containerizer; import com.google.cloud.tools.jib.api.DockerDaemonImage; import com.google.cloud.tools.jib.api.Jib; import com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath; // inspired by https://www.docker.com/blog/how-to-use-the-official-nginx-docker-image/ // create the image with jbang: "jbang CreateWebserver.java" // run the image with "docker run -it --rm -d -p 8080:80 --name web webserver" public class CreateWebserver { public static void main(String... args) throws Exception { Path root = Files.createTempDirectory("tmp"); Path htmlFolder = root.resolve("html"); Files.createDirectories(htmlFolder); Path indexFile = htmlFolder.resolve("index.html"); String content = "" + "\n" + "\n" + "\n" + " \n" + " Docker Nginx\n" + "\n" + "\n" + "

Hello from Nginx container

\n" + "

Created with jib

\n" + "\n" + ""; Files.write(indexFile, content.getBytes(StandardCharsets.UTF_8)); Jib.from("nginx:latest") .addLayer(Arrays.asList(htmlFolder), AbsoluteUnixPath.get("/usr/share/nginx/")) .containerize(Containerizer.to(DockerDaemonImage.named("webserver"))); } }