In this post under TestContainer, I will explain with example how to set environment variable before starting a container. For our example, we will use the latest “postgres” image from Docker Hub. According to “postgres” help page on Docker Hub we only need to set the environment variable “POSTGRES_PASSWORD” to start the postgres container and…… Continue reading Setting Environment Variable
Category: TestContainers
Communication between host and Container
In this post under TestContainer, I will show with example how to make the host communicate with the docker container. Below is the complete code for your reference. Main Class 1 package package3; 2 3 import org.testcontainers.containers.GenericContainer; 4 import org.testcontainers.utility.DockerImageName; 5 6 public class Example3 { 7 public static void main(String[] args) { 8 DockerImageName…… Continue reading Communication between host and Container
Accessing Container logs
In this post under TestContainers, I will show with example how to access container logs. Below is the complete main code for your reference. Main Class 1 package package2; 2 3 import org.testcontainers.containers.GenericContainer; 4 import org.testcontainers.utility.DockerImageName; 5 6 public class Example2 { 7 public static void main(String[] args) { 8 DockerImageName dockerImageName = DockerImageName.parse(“hello-world:latest”); 9…… Continue reading Accessing Container logs
Starting and Stopping Docker Containers
In this post under TestContainers, I will show with example how to start and stop a Docker container programmatically. Below is the complete main class for your reference. Main Class 1 package package1; 2 3 import org.testcontainers.containers.GenericContainer; 4 import org.testcontainers.utility.DockerImageName; 5 6 public class Example1 { 7 public static void main(String[] args) { 8 DockerImageName…… Continue reading Starting and Stopping Docker Containers