Potential issues when pulling Elasticsearch image
See original GitHub issueHi everyone, Could you help me here? My code can not load the testcontainer properties under the src/test/rescourse in CI docker maven enviroment.
But I can run it in local by Windows: C:/Users/myuser/.testcontainers.properties.
As we know, we can config our parameters follow below three ways.
- Environment variables
- .testcontainers.properties in user’s home folder. Example locations: Linux: /home/myuser/.testcontainers.properties Windows: C:/Users/myuser/.testcontainers.properties macOS: /Users/myuser/.testcontainers.properties
- testcontainers.properties on the classpath.
Because the CI machine, so I config it on the classpath (src/test/resources/*)
`public class ElasticInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { @ClassRule public static ElasticsearchContainer container = new ElasticsearchContainer();
/**
* @param applicationContext
*/
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
container.start();
TestPropertyValues.of("elasticsearch.host=" + container.getHost(),
"elasticsearch.port=" + container.getMappedPort(9200))
.applyTo(applicationContext);
}
}
@Testcontainers @SpringBootTest @ActiveProfiles(profiles = {“test”}) @ContextConfiguration(initializers = {ElasticInitializer.class}) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class PMBServiceImplTest { }`
16:48:42 08:48:42.863 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@49872d67 testClass = PMWHServiceImplTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@56303b57 testClass = PMWHServiceImplTest, locations = '{}', classes = '{class com....MetaApplication}', contextInitializerClasses = '[class .....impl.ElasticInitializer]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@338fc1d8, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@55cb6996, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@dc7df28, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@60f00693, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@7eecb5b8, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@448ff1a8], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null]. 16:48:42 08:48:42.925 [main] DEBUG org.testcontainers.utility.TestcontainersConfiguration - Testcontainers configuration overrides will be loaded from file:/root/.testcontainers.properties 16:48:42 08:48:42.940 [main] WARN org.testcontainers.utility.TestcontainersConfiguration - Attempted to read Testcontainers configuration file at file:/root/.testcontainers.properties but the file was not found. Exception message: FileNotFoundException: /root/.testcontainers.properties (No such file or directory) 16:48:42 08:48:42.944 [main] INFO org.testcontainers.utility.ImageNameSubstitutor - Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor') 16:48:43 08:48:42.952 [main] DEBUG org.testcontainers.utility.PrefixingImageNameSubstitutor - No prefix is configured 16:48:43 08:48:42.952 [main] DEBUG org.testcontainers.utility.ImageNameSubstitutor - Did not find a substitute image for docker.elastic.co/elasticsearch/elasticsearch:7.9.2 (using image substitutor: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')) 16:48:43 08:48:42.969 [main] DEBUG org.testcontainers.dockerclient.RootlessDockerClientProviderStrategy - $XDG_RUNTIME_DIR is not set. 16:48:43 08:48:42.969 [main] DEBUG org.testcontainers.dockerclient.RootlessDockerClientProviderStrategy - '/root/.docker/run' does not exist. 16:48:43 08:48:42.999 [main] DEBUG org.testcontainers.dockerclient.RootlessDockerClientProviderStrategy - '/run/user/0' does not exist. 16:48:43 08:48:42.999 [main] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Trying out strategy: UnixSocketClientProviderStrategy 16:48:43 08:48:43.001 [main] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock) 16:48:43 08:48:43.003 [main] INFO org.testcontainers.dockerclient.DockerMachineClientProviderStrategy - docker-machine executable was not found on PATH ([/opt/java/openjdk/bin, /usr/local/sbin, /usr/local/bin, /usr/sbin, /usr/bin, /sbin, /bin, /opt/apache-maven/bin]) 16:48:43 08:48:43.003 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were: 16:48:43 08:48:43.003 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock) 16:48:43 08:48:43.004 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - As no valid configuration was found, execution cannot continue 16:48:43 08:48:43.004 [main] DEBUG org.testcontainers.utility.PrefixingImageNameSubstitutor - No prefix is configured 16:48:43 08:48:43.004 [main] DEBUG org.testcontainers.utility.ImageNameSubstitutor - Did not find a substitute image for docker.elastic.co/elasticsearch/elasticsearch:7.9.2 (using image substitutor: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')) 16:48:43 08:48:43.007 [main] ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@4b45dcb8] to prepare test instance [.......dao.impl.PMWHServiceImplTest@3d08f3f5] 16:48:43 java.lang.IllegalStateException: Failed to load ApplicationContext
Issue Analytics
- State:
- Created a year ago
- Comments:12 (8 by maintainers)
For the second case you should use something like this
as mentioned by the exception message you just shared
Closing this because of lack of activity. @swift0303 feel free to reopen it with more info or join slack channel.