28 Eylül 2023 Perşembe

Testcontainers ImageFromDockerFile Sınıfı

Giriş
Şu satırı dahil ederiz
import org.testcontainers.images.builder.ImageFromDockerFile;
withDockerfile metodu
Örnek
Şöyle yaparız
ImageFromDockerfile image = new ImageFromDockerfile()
  .withDockerfile(Paths.get("Dockerfile.txt")); 

GenericContainer container = new GenericContainer(image)
  .withEnv(...)
  .withExposedPorts(...);
Dockerfile.txt şöyledir
// Dockerfile

FROM opensearchproject/opensearch:1.1.0

# Install a plugin
RUN /usr/share/opensearch/bin/opensearch-plugin install analysis-phonetic
withDockerfileFromBuilder metodu
Şöyle yaparız
@Rule
public GenericContainer<?> server = new GenericContainer(
  new ImageFromDockerFile()
    .withDockerfileFromBuilder(builder ->
      builder
        .from("alpine:3.16")
        .run("apk add --update nginx")
        .cmd("nginx", "-g", "deamon off;")
        .build()))
  .withExposedPorts(80);



Hiç yorum yok:

Yorum Gönder