dockercolima

Using colima, how can I run aarch64 and x86_64 docker images at the same time?


I currently use colima on my M2 mac to run docker containers that are x86 architecture-only (like the Oracle Free 23c image).

I have two VMs configured in colima:

$ colima start x86
...
$ docker run ...
$ colima list
PROFILE    STATUS     ARCH       CPUS    MEMORY    DISK     RUNTIME    ADDRESS
default    Stopped    aarch64    2       2GiB      60GiB               
x86        Running    x86_64     2       4GiB      60GiB    docker     
$ docker exec containerid bash -c "uname -a"
Linux 84a459c225c8 6.5.0-15-generic #15-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan  9 17:03:36 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Question:

Is the above scenario supported on colima/docker?


Solution

  • Update 14/10/2024 The Oracle 23ai Free version now officially supports Mac's ARM CPU, starting with the 23.5.0.0 release. See the screenshot below. No longer need to run Colima to run Oracle 23ai Free on Mac. enter image description here Below are the old answer before this update:

    Here is the solution I found today. I am running four containers in my docker-compose; unfortunately, 2 of them don't have native images for the Apple silicon processor.

    Step 1: start two Colima instances one with x86_64 profile and one with aarch64 profile.

    (PS: the first x86_64 or aarch64 are just colima profile names, you can name them in your way)

    colima start x86_64 --arch x86_64 --memory 8 --cpu 6
    colima start aarch64 --arch aarch64 --memory 2 --cpu 2
    

    Then you should see:

    peter@MacBook ~ % colima list
    PROFILE    STATUS     ARCH       CPUS    MEMORY    DISK     RUNTIME    ADDRESS
    aarch64    Running    aarch64    2       2GiB      60GiB    docker
    x86_64     Running    x86_64     6       8GiB      60GiB    docker
    

    Step 2: Use the docker context list command to view sock file information

    peter@MacBook ~ % docker context list
    NAME              DESCRIPTION                               DOCKER ENDPOINT                                        ERROR
    colima-aarch64    colima [profile=aarch64]                  unix:///Users/peter/.colima/aarch64/docker.sock
    colima-x86_64 *   colima [profile=x86_64]                   unix:///Users/peter/.colima/x86_64/docker.sock
    

    Step 3: Specify which container to use which architecture in the docker-compose file by adding this line:

    services:
      app1:
        container_name: x86_64_container
        volumes:
          - $HOME/.colima/x86_64/docker.sock:/var/run/docker.sock
      app2:
        container_name: aarch64_container
        volumes:
          - $HOME/.colima/aarch64/docker.sock:/var/run/docker.sock
    

    I managed to get my entire workload running in this way. The 2 CPU vs 6 CPU or 2 GiB memory vs 8 GiB memory are just initial setups, I haven't tested the performance yet. I doubt it will be quick. You will need to fine-tune it to suit your setup.

    Thanks