3

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 .

Omar Abo Elsoud
  • 154
  • 2
  • 12
  • Can't you use MariaDB instead of MySQL, I'm running MariaDB latest in a Macbook M1 without an issue :) The same should be usable with Test containers as well. – Chinthaka Dinadasa Sep 19 '21 at 16:59
  • please add `docker logs` for the DB container and the application container – Noam Yizraeli Sep 19 '21 at 17:22
  • @ChinthakaDinadasa I can not because we use SQL in the production environment – Omar Abo Elsoud Sep 19 '21 at 20:15
  • @NoamYizraeli . Here it is [logs](https://pastebin.com/bLcxWXpP) . I am not sure if it DB and the application container or not . I found more than logs files , I got the logs under the name of **com.docker.backend.log** – Omar Abo Elsoud Sep 19 '21 at 20:35
  • I'm confused, are these for the DB container? If it's both please separate them. and where is com.docker.backend.log? – Noam Yizraeli Sep 19 '21 at 20:39
  • @NoamYizraeli Sorry for late reply , There is no logs for DB container , as it is mentioned in the spring boot logs in the post . spring boot failed to pull SQL docker image and application failed to run .`'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` – Omar Abo Elsoud Sep 20 '21 at 17:46
  • Can you pull other images like `ubuntu` or `nginx`? – Noam Yizraeli Sep 20 '21 at 20:04
  • @NoamYizraeli I don't think test containers in spring boot supports pulling Ubuntu images . I don't know if you noticed that I mentioned I can pull sql docker image using docker pull command on the terminal , but it fails to pull it as test container using spring boot . the logs in pervious comment came from IntelliJ (spring boot ) while it tries to pull test container image – Omar Abo Elsoud Sep 20 '21 at 21:18

1 Answers1

0

I'm the current PM for Azure SQL Edge at Microsoft dropping by with an update to share. Docker Desktop v4.16 introduced beta support for the Virtualization framework, meaning you can now run x86/amd64 based SQL Server containers on M1/M2 silicon with macOS 13. This will be our recommended path for running SQL server containers on ARM based macOS going forward as it will enable you to develop against SQL Server 2017-2022 in addition to Azure SQL Edge. For a walkthrough on how to enable the feature and run a SQL Server 2022 container on macOS, check out https://devblogs.microsoft.com/azure-sql/development-with-sql-in-containers-on-macos/

SQLDBA
  • 1
  • 1
    The have fixed M1 issue in the new releases if you the test containers fails to run on M1 . you just need to migrate for testContiner new release – Omar Abo Elsoud Feb 13 '23 at 15:17