codeape
codeape

Reputation: 100886

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?

Upvotes: 2

Views: 2369

Answers (2)

peterpengnz
peterpengnz

Reputation: 6072

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

Upvotes: 3

codeape
codeape

Reputation: 100886

This is addressed in https://github.com/abiosoft/colima/issues/1127 .

The key is using docker contexts to control multiple docker daemons from a docker client: https://docs.docker.com/engine/manage-resources/contexts/ .

From the Github issue:

You can run as many instances as you want concurrently. Passing an extra argument after the start command creates a new instance with the argument as the instance name.

# start the default one for arm containers e.g. elasticsearch
colima start 

# start another one for oracle db 
colima start oracle --arch x86_64

They would both run fine. The only issue would be with switching docker contexts for the docker command.

You can either use docker context use or set the DOCKER_HOST environment variable.

  • to point to the default context: docker context use colima
  • to point to the oracle context: docker context use colima-oracle
  • to check the current context: docker context show
  • to list contexts: docker context ls

Upvotes: 2

Related Questions