MSSQLServerContainer does not allow azure-sql-edge
On an Apple M1, Microsoft's mcr.microsoft.com/mssql/server fails because the sqlcmd is not supported on ARM64; however, Microsoft makes an mcr.microsoft.com/azure-sql-edge Azure SQL Edge container that does work and claims to be fully T-SQL compatible (see here).
I managed to build my own provider that re-uses the MSSQLServerContainer, but with a different image:
/**
* Uses a {@link MSSQLServerContainer} with a `mcr.microsoft.com/azure-sql-edge` image (default: "latest") in place of
* the standard ` mcr.microsoft.com/mssql/server` image
*/
class AzureSqlEdgeContainerProvider extends JdbcDatabaseContainerProvider {
private static final String NAME = 'azuresqledge'
@Override boolean supports(String databaseType) {
return databaseType.equals(NAME);
}
@Override JdbcDatabaseContainer newInstance() {
return newInstance('latest');
}
@Override JdbcDatabaseContainer newInstance(String tag) {
def taggedImageName = DockerImageName.parse("mcr.microsoft.com/azure-sql-edge")
.withTag(tag)
.asCompatibleSubstituteFor("mcr.microsoft.com/mssql/server") // From MSSQLServerContainer.DEFAULT_IMAGE_NAME
return new MSSQLServerContainer(taggedImageName);
}
}
I had to use a different databaseType name (azuresqledge instead of sqlserver) to prevent the two providers from competing. Perhaps there's a better way to avoid that competition without having to change the databaseType name.
Or perhaps there's a way to modify MSSQLServerContainer/...Provider to accept either image name.
Nonetheless, the above provider works fine with my limited, local testing thus far.
Hey @Trinition, thanks a lot for sharing your implementation with the community 🙌
The lack of configurability of the image used by the JdbcDatabaseContainerProvider is discussed in https://github.com/testcontainers/testcontainers-java/issues/4. As I see it, if we solve this issue, it would solve this issue as well.
MSSQL's JDBC Driver 10.1+ enables encrypt=true by default, but not trustServerCertificate=true. You can either add certificate trusting...
return new MSSQLServerContainer(taggedImageName)
.withUrlParam('trustServerCertificate', 'true')
Or disable encrypt...
return new MSSQLServerContainer(taggedImageName)
.withUrlParam('encrypt', 'false')
@Trinition could you please elaborate more how to make image mcr.microsoft.com/azure-sql-edge work with MSSQLServerContainer. I am trying to make it work on my apple M1 pro .. without success so far...
@gmelekh I apologize, but I don't recall what I did. The project I was doing this for got shelved last year, so I'm not currently working on it, and my memory has faded a lot.
@gmelekh the little bi I was able to scape back together:
- I implemented a subclass of JdbcDatabaseContainerProvider (see the initial post above)
- That uses the "mcr.microsoft.com/azure-sql-edge" image
- My connection string looks like the following (note the "azuresqledge" matches the custom provider): jdbc:tc:azuresqledge://localhost;instance=SQLEXPRESS:1434;databaseName=MyDbName;encrypt=true;trustServerCertificate=true
I am getting this error when try to start the container
com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
It is now possible to use azure sql edge with TC. I am currently on version 1.20.*
@Bean
@ServiceConnection
fun mssqlContainer(): MSSQLServerContainer<*> {
val imageName = DockerImageName.parse("mcr.microsoft.com/azure-sql-edge:1.0.7")
.asCompatibleSubstituteFor("mcr.microsoft.com/mssql/server")
return MSSQLServerContainer(imageName)
.acceptLicense()
}
azure-sql-edge will be retired https://azure.microsoft.com/nb-no/updates?id=azure-sql-edge-retirement and as mentioned in previous comment can me marked a compatible substitute.
For those with M1 hitting a similar issue something along theses lines helps
final DockerImageName imageName = DockerImageName.parse("mcr.microsoft.com/azure-sql-edge:latest")
.asCompatibleSubstituteFor("mcr.microsoft.com/mssql/server");
final MSSQLServerContainer<?> container = new MSSQLServerContainer<>(imageName).withUrlParam("trustServerCertificate", "true")
.acceptLicense()
.withConnectTimeoutSeconds(180)
.waitingFor(Wait.forListeningPort());
container.addEnv("SA_PASSWORD", container.getPassword());
container.withReuse(true);
Unexpected end of prelogin response after 0 bytes read
Mar 07, 2025 10:44:41 AM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
WARNING: ConnectionID:61 ClientConnectionId: 668853e6-d7f6-4280-90d9-c31326f42b94 Prelogin error: host localhost port 53620 Unexpected end of prelogin response after 0 bytes read
Mar 07, 2025 10:44:41 AM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
WARNING: ConnectionID:61 ClientConnectionId: f96c426a-37f4-4808-99dd-9aa799cf6121 Prelogin error: host localhost port 53620 Unexpected end of prelogin response after 0 bytes read
Mar 07, 2025 10:44:42 AM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
WARNING: ConnectionID:62 ClientConnectionId: ee528850-fb61-4053-bf17-d85df59f9794 Prelogin error: host localhost port 53620 Unexpected end of prelogin response after 0 bytes read
Mar 07, 2025 10:44:42 AM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
WARNING: ConnectionID:62 ClientConnectionId: 937a5f44-3b83-4e73-8244-5751e7e52189 Prelogin error: host localhost port 53620 Unexpected end of prelogin response after 0 bytes read
Mar 07, 2025 10:44:42 AM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
WARNING: ConnectionID:63 ClientConnectionId: 2b439520-0f2b-44dd-bb5d-ce79638da845 Prelogin error: host localhost port 53620 Unexpected end of prelogin response after 0 bytes read
Mar 07, 2025 10:44:42 AM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
WARNING: ConnectionID:63 ClientConnectionId: 6f035d10-28aa-42ce-b29e-25245e367d17 Prelogin error: host localhost port 53620 Unexpected end of prelogin response after 0 bytes read
Mar 07, 2025 10:44:42 AM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
WARNING: ConnectionID:64 ClientConnectionId: 816a9359-f32b-4c29-9db9-491757e82345 Prelogin error: host localhost port 53620 Unexpected end of prelogin response after 0 bytes read
Mar 07, 2025 10:44:42 AM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
WARNING: ConnectionID:64 ClientConnectionId: 992af21e-4157-49c7-974d-3ad9cd2714aa Prelogin error: host localhost port 53620 Unexpected end of prelogin response after 0 bytes read
Mar 07, 2025 10:44:42 AM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
WARNING: ConnectionID:65 ClientConnectionId: a291f4b0-f7b2-4856-be20-33b94440f232 Prelogin error: host localhost port 53620 Unexpected end of prelogin response after 0 bytes read
[main] INFO tc.mcr.microsoft.com/azure-sql-edge:latest - Container mcr.microsoft.com/azure-sql-edge:latest started in PT9.055S
[main] INFO tc.mcr.microsoft.com/azure-sql-edge:latest - Container is started (JDBC URL: jdbc:sqlserver://localhost:53620;encrypt=false;trustServerCertificate=true)
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.