skip to Main Content

This Dockerfile works fine on Windows/Linux

FROM centos:centos7
RUN yum -y install python3 gcc
RUN pip3 install --upgrade pip
RUN pip3 install psutil

I build the image by doing

docker build -t anytag .

enter image description here

but the same Dockerfile fails on MacOS. I tried in two different Macs (M1 chip)

The error I get is

#0 93.73   gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=591 -DPSUTIL_LINUX=1 -I/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-aarch64-3.6/psutil/_psutil_common.o
#0 93.73   psutil/_psutil_common.c:9:20: fatal error: Python.h: No such file or directory
#0 93.73    #include <Python.h>
#0 93.73                       ^
#0 93.73   compilation terminated.
#0 93.73   error: command 'gcc' failed with exit status 1
#0 93.73   ----------------------------------------
#0 93.73   ERROR: Failed building wheel for psutil
#0 93.73   Building wheel for pendulum (pyproject.toml): started
#0 94.04   Building wheel for pendulum (pyproject.toml): finished with status 'done'
#0 94.04   Created wheel for pendulum: filename=pendulum-2.1.2-cp36-cp36m-manylinux_2_17_aarch64.whl size=109769 sha256=2373b525a3ca7c5991eb07b0fb7fd31663a114e998480b9d4e09fe658f154152
#0 94.04   Stored in directory: /home/etl/.cache/pip/wheels/c7/33/5b/9bd231ee982125a3e4eaa5c77a04de43eba25ee940cfb5a84a
#0 94.04 Successfully built pendulum
#0 94.04 Failed to build psutil
#0 94.04 ERROR: Could not build wheels for psutil, which is required to install pyproject.toml-based projects
------
failed to solve: executor failed running [/bin/sh -c pip3 install --user etl --upgrade pip     && pip3 install --user etl -r /tmp/python_requirements.txt]: exit code: 1

enter image description here

I know I can fix this problem in MacOS by installing python-devel in centos7, but I want to understand why the images behave differently.

Thanks.

2

Answers


  1. Chosen as BEST ANSWER

    After a long search, I found this article https://pythonspeed.com/articles/docker-build-problems-mac/

    The problem was the chip architecture (arm). The solutions proposed in the article above are working (either building from the source, getting precompiled binaries, or adding --platform linux/amd64 when building with Docker)


  2. The suggested answer by freddy worked for me. I added --platform linux/amd64 to my build command. I plan to add it to all my future docker commands on my m1 arm, though I admit I don’t know which commands need it or not.

    Example commands I ran:

    docker push --platform linux/amd64 brandojazz/iit-term-synthesis:test_arm
    docker pull --platform linux/amd64 brandojazz/iit-term-synthesis:test_arm
    docker build --platform linux/amd64 -f ~/iit-term-synthesis/Dockerfile_arm -t brandojazz/iit-term-synthesis:test_arm ~/iit-term-synthesis/
    docker run -v /Users/brandomiranda/iit-term-synthesis:/home/bot/iit-term-synthesis 
               -v /Users/brandomiranda/pycoq:/home/bot/pycoq 
               -v /Users/brandomiranda/ultimate-utils:/home/bot/ultimate-utils 
               -v /Users/brandomiranda/proverbot9001:/home/bot/proverbot9001 
               -v /Users/brandomiranda/data:/home/bot/data 
               --platform linux/amd64 
               -ti brandojazz/iit-term-synthesis:test bash
    

    see for details: https://pythonspeed.com/articles/docker-build-problems-mac/

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