According to Docker official website , Docker doesn't support SQL image for M1 processors ; however , it supports installing it by passing " --platform linux/x86_64 mysql" .
Actually , SQL docker is pulled successfully using this command
docker pull --platform linux/x86_64 mysql
the output :
Using default tag: latest
latest: Pulling from library/mysql
a330b6cecb98: Pull complete
9c8f656c32b8: Pull complete
88e473c3f553: Pull complete
062463ea5d2f: Pull complete
daf7e3bdf4b6: Pull complete
1839c0b7aac9: Pull complete
cf0a0cfee6d0: Pull complete
1b42041bb11e: Pull complete
10459d86c7e6: Pull complete
b7199599d5f9: Pull complete
1d6f51e17d45: Pull complete
50e0789bacad: Pull complete
Digest: sha256:99e0989e7e3797cfbdb8d51a19d32c8d286dd8862794d01a547651a896bcf00c
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:late
Now , I want to use SQL container in my integration test , but docker fails to pull SQL.
The code used to initialize SQL test container
@DynamicPropertySource
static void dynamicPropertySource(DynamicPropertyRegistry dynamicPropertyRegistry) {
MySQLContainer<?> container = new MySQLContainer<>("mysql:8.0.26")
.withDatabaseName("sympl")
.withUsername("test")
.withPassword("test")
.withCommand("docker pull --platform linux/x86_64 mysql");
dynamicPropertyRegistry.add("spring.datasource.url", () -> container.getJdbcUrl());
dynamicPropertyRegistry.add("spring.datasource.username", () -> container.getUsername());
dynamicPropertyRegistry.add("spring.datasource.password", () -> container.getPassword());
container.start();
}
I tried to write the code withCommand()
and without .withCommand
.
After I run the test cases , it gives fails with the following logs :
17:18:25.003 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.003 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.005 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.005 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.015 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@3faf2e7d testClass = CustomerApiIntegrationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@4648ce9 testClass = CustomerApiIntegrationTests, locations = '{}', classes = '{class com.sympl.customer.CustomersApplication}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@78fa769e, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2c78324b, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@3fd11d55, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@6ca18a14, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@1ec9bd38, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@cd1e646, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@aa1b54d2, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@5890e879], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> false]], class annotated with @DirtiesContext [false] with mode [null].
17:18:25.021 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.021 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.088 [main] DEBUG org.springframework.core.env.StandardEnvironment - Activating profiles [test]
17:18:25.094 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.3)
2021-09-19 17:18:26.039 INFO 9715 --- [ main] o.t.d.DockerClientProviderStrategy : Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
2021-09-19 17:18:27.294 INFO 9715 --- [ main] o.t.d.DockerClientProviderStrategy : Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
2021-09-19 17:18:27.299 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Docker host IP address is localhost
2021-09-19 17:18:27.365 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Connected to docker:
Server Version: 20.10.8
API Version: 1.41
Operating System: Docker Desktop
Total Memory: 1988 MB
2021-09-19 17:18:27.369 INFO 9715 --- [ main] o.t.utility.ImageNameSubstitutor : Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
2021-09-19 17:18:27.547 INFO 9715 --- [ main] o.t.utility.RegistryAuthLocator : Credential helper/store (docker-credential-desktop) does not have credentials for index.docker.io
2021-09-19 17:18:28.202 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
2021-09-19 17:18:28.203 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Checking the system...
2021-09-19 17:18:28.203 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker server version should be at least 1.6.0
2021-09-19 17:18:28.322 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker environment should have more than 2GB free disk space
2021-09-19 17:18:28.388 INFO 9715 --- [ main] [mysql:8.0.26] : Pulling docker image: mysql:8.0.26. Please be patient; this may take some time but only needs to be done once.
2021-09-19 17:18:32.326 INFO 9715 --- [stream--1235448] [mysql:8.0.26] : Starting to pull image
2021-09-19 17:18:32.369 INFO 9715 --- [stream--1235448] [mysql:8.0.26] : Pulling image layers: 0 pending, 0 downloaded, 0 extracted, (0 bytes/0 bytes)
2021-09-19 17:18:32.422 ERROR 9715 --- [ main] o.s.boot.SpringApplication : Application run failed
org.testcontainers.containers.ContainerLaunchException: Container startup failed
at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:330) ~[testcontainers-1.15.3.jar:na]
at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:311) ~[testcontainers-1.15.3.jar:na]
at com.sympl.customer.api.CustomerApiIntegrationTests.dynamicPropertySource(CustomerApiIntegrationTests.java:79) ~[test-classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
Here is the docker logs
I am sure there is a workaround for this , but I couldn't find it till now .