-
Notifications
You must be signed in to change notification settings - Fork 581
DB2 on Mac ARM64
There is currently no IBM DB2 readily available that can run on ARM64 architecture (Mac M1/M2). This makes it impossible for developers using these computers to exercise DB2 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-db2 --hostname test-db2 -d -p 50000:50000 -e LICENSE=accept -e DB2INSTANCE=spring -e DB2INST1_PASSWORD=spring -e DBNAME=dataflow --privileged=true ibmcom/db2:latest
-
Stop the container w/ the following command:
docker stop test-DB2
-
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
Db2Container
in your tests such as:Db2Container container = new Db2Container( DockerImageName.parse(DB2ServerContainer.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 the DB2_11_5_ContainerSupport interface in your test class which will handle the above setup. |
-
Ensure DB2 container running locally (above)
-
Include the DB2 driver by building Dataflow w/ the
local-dev-db2
profile as follows:./mvnw clean install -DskipTests -s .settings.xml -Plocal-dev-db2
-
Set the following env vars before running Dataflow:
export SPRING_DATASOURCE_URL="jdbc:db2://localhost:50000/dataflow" export SPRING_DATASOURCE_USERNAME=spring export SPRING_DATASOURCE_PASSWORD=spring export SPRING_DATASOURCE_DRIVER_CLASS_NAME=com.ibm.db2.jcc.DB2Driver
-
Run the Dataflow server either from w/in IDEA or
java -jar
Here are some useful aliases for starting/stopping an DB2 database in Docker:
alias db2-start="docker run --name test-db2 --hostname test-db2 -d -p 50000:50000 -e LICENSE=accept -e DB2INSTANCE=spring -e DB2INST1_PASSWORD=spring -e DBNAME=dataflow --privileged=true ibmcom/db2:latest "
alias db2-stop="docker stop test-db2 "
alias db2-kill="docker stop test-db2 && docker rm test-db2 "
alias colima-start="colima start --arch x86_64 --memory 4 "
alias colima-stop="colima stop "