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:
Ran
docker run -it <image> bashto verify the/usr/src/apppath is correct.Verified the path of the Python3 binary within docker,
which python3.Ran the image,
python3 /usr/src/app/hello_world.pyand the output was correct.Deleted and recreated jobs, job definitions and repositories.
I hope this is enough detail to help me troubleshoot the issue.
Thanks for reading.
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
inspectcommand, you are referencing the same tag as thebuildcommand, instead of using thelatesttag every time. That's probably why you're seeing inconsistent results.