edean
edean

Reputation: 496

ibmcom/db2 docker image fails on m1

I'm having trouble setting up DB2 on macOS via Docker on my M1-Max MacBook Pro (32 GB RAM). I already had a look at this question, which might be related, however there is not a lot of information and I cannot exactly say, if it is about the exact same thing. I set up following docker-compose.yml:

version: '3.8'

services:
  db2:
    image: ibmcom/db2
    platform: linux/amd64
    container_name: db2-test
    privileged: true
    environment:
      LICENSE: "accept"
      DB2INSTANCE: "db2dude"
      DB2INST1_PASSWORD: "db2pw"
      DBNAME: "RC1DBA"
      BLU: "false"
      ENABLE_ORACLE_COMPATIBILITY: "false"
      UPDATEVAIL: "NO"
      TO_CREATE_SAMPLEDB: "false"
      REPODB: "false"
      IS_OSXFS: "true"
      PERSISTENT_HOME: "true"
      HADR_ENABLED: "false"
      ETCD_ENDPOINT: ""
      ETCD_USERNAME: ""
      ETCD_PASSWORD: ""
    volumes: 
       - ~/workspace/docker/db2-error/db2/database:/database
       - ~/workspace/docker/db2-error/db2/db2_data:/db2_data
    ports:
      - 50000:50000

on my Intel-MacBook, this spins up without any issue, on my M1-MacBook however I see after Task #4 finished, I see following portion inside of the STDOUT:

DBI1446I  The db2icrt command is running.


DBI1070I  Program db2icrt completed successfully.


(*) Fixing /etc/services file for DB2 ... 
/bin/bash: db2stop: command not found

From what I could figure out, the presence of (*) Fixing /etc/services file for DB2 ... already seems to be wrong (since it does not appear in my intel log and does not sound like everything's fine) and the /bin/bash: db2stop: command not found appears due to line 81 of /var/db2_setup/include/db2_common_functions, which states su - ${DB2INSTANCE?} -c 'db2stop force'. As far as I understand, su - should run with the path of the target user. In every single .profile or .bashrc in the home directory, the ~/sqllib/db2profile is being sourced (via . /database/config/db2dude/sqllib/db2profile).

However, when as root inside of the container (docker exec -it db2-test bash), calling su - db2dude -c 'echo $PATH', it prints /usr/local/bin:/bin:/usr/bin. Therefore, the PATH obviously is not as expected.

Maybe someone can figure out, what's happening at this point. I also tried running Docker with "new Virtualization framework", which did not change anything. I assume, Dockers compatibility magic might not be perfect, however I'm looking forward to find some kind of workaround, maybe by building an image upon ibmcom/db2.

I highly appreciate your time and advice. Thanks a lot in advance.

Upvotes: 4

Views: 4782

Answers (4)

Adrian
Adrian

Reputation: 570

A working solution for Apple Silicon (in my case Apple M3) with Docker Desktop for ibmcom/db2 image.

Most important options to apply:

  1. In Docker Desktop go to Settings -> General -> unselect "Use Rosetta for x86_64/amd64 emulation on Apple Silicon"
  2. add ENV variable DOCKER_DEFAULT_PLATFORM=linux/amd64 by running the command in console export DOCKER_DEFAULT_PLATFORM=linux/amd64 or add it directly before the container start command (as in examples bellow)
  3. use --platform=linux/amd64 setting when running docker container
  4. use --privileged=true setting when running container, otherwise db2 lacks access to run starting scripts

To run the container:

export DOCKER_DEFAULT_PLATFORM=linux/amd64 && docker run -it --name db2 -e DBNAME=test -e DB2INST1_PASSWORD=testpwd -e LICENSE=accept -p 50000:50000 --privileged=true --platform=linux/amd64 ibmcom/db2

Second solution to use with docker-compose.yml:

version: '3.8'

services:
  db2:
    image: ibmcom/db2
    platform: linux/amd64
    privileged: true
    environment:
      - LICENSE=accept
      - DB2INST1_PASSWORD=testpwd
      - DBNAME=test
    ports:
      - "50000:50000"
    container_name: db2

To run with docker-compose:

export DOCKER_DEFAULT_PLATFORM=linux/amd64 && docker-compose up

To login via DB client (for example Dbeaver) use these connection settings:

host: localhost
port: 50000
user: db2inst1
password: testpwd
database: test

Side notes that helped me finding the solution:

  • remember to remove container between settings changes
  • remember to remove volumes between settings changes

Upvotes: 0

Jon Bartlett
Jon Bartlett

Reputation: 73

I got this working on Mac Silicon using Colima https://github.com/abiosoft/colima

brew install colima
colima start --arch x86_64
docker run -h db2server --name db2server --restart=always --detach --privileged=true -p  50000:50000 --env-file env_list.txt -v ~/Documents/projects/docker/database icr.io/db2_community/db2

Upvotes: 1

horstwilhelm
horstwilhelm

Reputation: 306

As stated in @mshabou's answer, there is no support yet. One way you can still make it work is by prepending your Docker command with DOCKER_DEFAULT_PLATFORM=linux/amd64 or executing export DOCKER_DEFAULT_PLATFORM=linux/amd64 in your shell before starting the container.

Alternatively, you can also use colima. Install colima as described on their GitHub page and then start it in emulated mode like colima start --arch x86_64. Now you will be able to use your ibmcom/db2 image the way you're used to (albeit with decreased performance).

Upvotes: 2

mshabou
mshabou

Reputation: 592

db2 is not supported on ARM architecture, only theses Architectures are supported: amd64, ppc64le, s390x

https://hub.docker.com/r/ibmcom/db2

Upvotes: 1

Related Questions