skip to Main Content

I have an AWS Batch job that returns the following error when it attempts to run a Docker image in ECR:

exec /usr/local/bin/python3: exec format error

I built the image on macOS with an M1 chip. Because of this I built the image with the following command using the --platform linux/amd64 parameter. I have also tried --platform linux/x86_64:

docker buildx build --no-cache --platform linux/amd64 -t repository-name:latest .

I then ran docker inspect --format='{{.Architecture}}' repository-name:latest and it returned arm64. The CPU architecture for the container is X86_64. Is this where my issue lies, and if so, what is incorrect with my build step?

This is my Docker file:


FROM python:3.9

WORKDIR /usr/src/app/

COPY . /usr/src/app/

RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 80

ENV NAME World

CMD ["python3", "/usr/src/app/hello_world.py"]

This is my hello_world.py script:

import pandas as pd

print('hello world!')

Additional troubleshooting:

  1. Ran docker run -it <image> bash to verify the /usr/src/app path is correct.

  2. Verified the path of the Python3 binary within docker, which python3.

  3. Ran the image, python3 /usr/src/app/hello_world.py and the output was correct.

  4. Deleted and recreated jobs, job definitions and repositories.

I hope this is enough detail to help me troubleshoot the issue.

Thanks for reading.

2

Answers


  1. Chosen as BEST ANSWER

    I reached a solution. Despite using --no-cache in the build command, local layers were apparently cached and after I ran docker system prune -a, built again and inspected the build, it was in the correct architecture, amd64. I pushed to the repository and it ran correctly.


  2. exec format error

    This error is typical of mismatched CPU architectures, so yes your assumption is correct.

    Your command to build the container image for Intel/AMD 64-bit is correct. I suspect that you are using a mismatched container image tag when you’re attempting to deploy the container to the AWS Batch service. Make sure that when you run the inspect command, you are referencing the same tag as the build command, instead of using the latest tag every time. That’s probably why you’re seeing inconsistent results.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search