-
Notifications
You must be signed in to change notification settings - Fork 583
MSSQL on Mac ARM64
There is currently no Microsoft SQL Server (MSSQL) readily available that can run on ARM64 architecture (Mac M1/M2). This makes it impossible for developers using these computers to exercise MSSQL functionality/tests locally. This guide show how to work around this limitation.
The solution is to run a tool (Colima) that allows you to spin up x86_64
software on Apple M chips and then start the container as you normally would (docker run
or via Testcontainers).
|
If Homebrew is not installed properly for M1/M2 you will run into issues w/ Colima. |
Execute which homebrew
and…
No matter where you are running the container from, you must always have Colima started prior to running the container.
-
Run Colima w/ the following command:
colima start --arch x86_64 --memory 4
-
Ensure Colima is started (above)
-
Start the container w/ the following command:
docker run --name test-mssql --hostname test-mssql -d -p 1433:1433 -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=MSSqlServer_RootPassword1 mcr.microsoft.com/mssql/server:2022-latest
-
Stop the container w/ the following command:
docker stop test-mssql
-
Stop Colima w/ the following command:
colima stop
-
Ensure Colima is started (above)
-
Set the following environment variables:
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock export DOCKER_HOST="unix://${HOME}/.colima/docker.sock"
-
Create and start an
MSSQLServerContainer
in your tests such as:MSSQLServerContainer container = new MSSQLServerContainer( DockerImageName.parse(MSSQLServerContainer.IMAGE).withTag("2022-latest")) .acceptLicense(); container.start();
-
Once you are finished running the container you can stop Colima w/ the following command:
colima stop
💡
|
You can also simply implement one of the SqlServer_2017_ContainerSupport, SqlServer_2019_ContainerSupport, or SqlServer_2022_ContainerSupport interfaces in your test class which will handle the above setup. |
-
Ensure MSSQL container running locally (above)
-
Include the MSSQL driver by building Dataflow w/ the
local-dev-mssql
profile as follows:./mvnw clean install -DskipTests -s .settings.xml -Plocal-dev-mssql
-
Set the following env vars before running Dataflow:
export SPRING_DATASOURCE_URL="jdbc:sqlserver://localhost:1433;encrypt=true;trustServerCertificate=true" export SPRING_DATASOURCE_USERNAME=sa export SPRING_DATASOURCE_PASSWORD="MSSqlServer_RootPassword1" export SPRING_DATASOURCE_DRIVER_CLASS_NAME=com.microsoft.sqlserver.jdbc.SQLServerDriver
ℹ️
|
MSSQL does not allow bootstrap creation of a database via an env var, as such the master database is used and there is no database property set in the url
|
-
Run the Dataflow server either from w/in IDEA or
java -jar
Here are some useful aliases for starting/stopping an MSSQL database in Docker:
alias mssql-start="docker run --name test-mssql --hostname test-mssql -d -p 1433:1433 -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=MSSqlServer_RootPassword1 mcr.microsoft.com/mssql/server:2022-latest "
alias mssql-stop="docker stop test-mssql "
alias mssql-kill="docker stop test-mssql && docker rm test-mssql "
alias colima-start="colima start --arch x86_64 --memory 4 "
alias colima-stop="colima stop "