Troubleshooting "docker image targets wrong architecture" error

Problem:

When trying to use an arm-based Docker image with the Docker executor, you may see the following error when trying to use an image built for the wrong architecture:

WARNING: docker image targets wrong architecture (found arm64 but need [amd64 i386 386])

Solutions:

  • Solution 1
    • In order to run arm-based images with the Docker executor, you will need to specify an arm resource class. For a list of available resource classes, please check the following page:

      https://discuss.circleci.com/t/product-launch-arm-docker-preview/48601

      Here is an example using the resource class arm-medium:

      version: 2.1
      
      jobs:
        test:
          docker:
            - image: cimg/base:stable
          resource_class: arm-medium
          steps:
            - checkout
            - run: 
                name: Test
                command: |
                  echo "test"
      workflows:
        arm-workflow:
          jobs:
            - test
  • Solution 2
    • Arm-based Docker images can also be executed on the Machine executor by utilizing the command docker run and passing in the architecture for the --platform option.

      Here is a sample config.yml file showing this implementation using the docker image ruby:3.2.2-slim with the Machine executor image ubuntu-2004:2022.04.1 and logging out the architecture:

      version: 2.1
      
      jobs:
        test:
          machine:
            image: ubuntu-2004:current
          resource_class: arm.medium
          steps:
            - checkout
            - run: 
                name: Start arm docker container
                command: |
                  docker run -idt --platform linux/arm64/v8 --name ruby ruby:3.2.2-slim
                  docker exec -it ruby bash -c "uname -m"
      
      workflows:
        arm-workflow:
          jobs:
            - test

Outcome:

The "targets wrong architecture" error should no longer show if the architecture of the image you are trying to run matches the one of the executor specified in your config.yml file.

Additional Resources: 

Please see the following resources for additional information on the Machine executor, and how to work with multi-platform Docker images.

Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Article is closed for comments.