Search code examples
dockerdocker-composearm64

How to use a x86-64 docker image on arm64 with docker compose


I use docker compose to run existing docker images behind a Traefik proxy on a Raspberry Pi. The workflow is like creating a docker-compose.yml file and running docker compose up -d.

Sometimes it is difficult to find a maintained version of a docker image for arm64, but x86-64 (or amd64) images are available. One example is Dovecot: https://hub.docker.com/r/dovecot/dovecot

So how I can use such an image without maintaining my own version of it?

I don't care if docker has to build the image in the background every time there comes an update, but I don't want to keep track of upstream Dockerfile changes, etc. I understand that there are cases, where this is not a trivial job (like cross-compiling binaries), but in my scenario, it is safe to assume, that all dependencies are available in arm64 and there is no compiling involved.


Solution

  • The minimum effort is rebuilding the image on an arm64 machine or for arm64 with buildx - if you are lucky, it will work without adjustments of the dockerfile: https://github.com/dovecot/docker/blob/main/2.3.20/Dockerfile

    Edit: However, simply building this image for arm64 will not be possible because it uses some Debian packages, which are not available for arm64.

    But there is an image that fulfills the stated assumption (blackflysolutions/dovecot). For such an image it is as simple as replacing the image attribute of the service with a build attribute:

    version: "3"
    
    services:
      dovecot:
        build: "https://github.com/BlackflySolutions/dovecot.git#master"
        ports:
          - "143"
        volumes:
          - "~/dovecot/config:/config:rw"
          - "~/dovecot/mail:/mail:rw"
    

    When running docker compose up it automatically downloads and builds the image based on the Dockerfile in the git repository. When updating the image it might be required to use --build or --force-recreate.

    More details on how the build attribute can be customized can be found in the documentation. With recent versions, it is also possible to target a sub-directory of a repository.