Dockerfile for M1

I received my new M1 Mac last night, and now must learn how to work with ARM. Could someone please check my Dockerfile to see what is wrong? It builds fine, but importing numba in python results in an error. My google-fu has not resulted in anything.

Error

Python 3.8.3 | packaged by conda-forge | (default, Jun  1 2020, 17:03:52) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from numba import njit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/envs/stringdist/lib/python3.8/site-packages/numba/__init__.py", line 39, in <module>
    from numba.core.decorators import (cfunc, generated_jit, jit, njit, stencil,
  File "/opt/conda/envs/stringdist/lib/python3.8/site-packages/numba/core/decorators.py", line 12, in <module>
    from numba.stencils.stencil import stencil
  File "/opt/conda/envs/stringdist/lib/python3.8/site-packages/numba/stencils/stencil.py", line 11, in <module>
    from numba.core import types, typing, utils, ir, config, ir_utils, registry
  File "/opt/conda/envs/stringdist/lib/python3.8/site-packages/numba/core/ir_utils.py", line 16, in <module>
    from numba.core.extending import _Intrinsic
  File "/opt/conda/envs/stringdist/lib/python3.8/site-packages/numba/core/extending.py", line 18, in <module>
    from numba.core.pythonapi import box, unbox, reflect, NativeValue  # noqa: F401
  File "/opt/conda/envs/stringdist/lib/python3.8/site-packages/numba/core/pythonapi.py", line 12, in <module>
    from numba import _helperlib
ImportError: /lib/aarch64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /opt/conda/envs/stringdist/lib/python3.8/site-packages/numba/_helperlib.cpython-38-aarch64-linux-gnu.so)
>>> 

Dockerfile

FROM debian:buster-slim

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

RUN apt-get update -q && \
    apt-get install -q -y \
        bzip2 \
        ca-certificates \
        git \
        libglib2.0-0 \
        libsm6 \
        libxext6 \
        libxrender1 \
        mercurial \
        subversion \
        wget \
        htop

ENV PATH /opt/conda/bin:$PATH

CMD [ "/bin/bash" ]

# Leave these args here to better use the Docker build cache
RUN wget --quiet https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh -O miniconda.sh && \
    mkdir -p /opt && \
    sh miniconda.sh -b -p /opt/conda && \
    ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
    echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
    echo "conda activate base" >> ~/.bashrc && \
    find /opt/conda/ -follow -type f -name '*.a' -delete && \
    find /opt/conda/ -follow -type f -name '*.js.map' -delete && \
    /opt/conda/bin/conda clean -afy

RUN conda create -n stringdist python=3.8.3 && \
    conda install -y -n stringdist pep8 pylint numpy scipy notebook

RUN conda config --add channels c4aarch64 && \
    conda config --add channels conda-forge && \
    conda install -y -n stringdist -c numba numba

M1 Mac running Docker version 20.10.3, build 48d30b5.

Thanks!

Hi @ryanchien

The error is due to a missing versioned GLIBC symbol, probably because something in Numba (_helperlib.so.x) is linked against a glibc newer than the one you have (potentially due to using the Centos 7 compilers).

Entirely guessing… perhaps try installing this: https://anaconda.org/conda-forge/sysroot_linux-aarch64 into your environment.

xref for guess: Knowledge base — conda-forge 2021.02.15 documentation

Thanks Stuart. Wasn’t able to get the the Debian image working, although the following Ubuntu image works just fine.

FROM ubuntu:20.10

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

RUN apt-get update -q && \
    apt-get install -q -y \
        bzip2 \
        ca-certificates \
        git \
        libglib2.0-0 \
        libsm6 \
        libxext6 \
        libxrender1 \
        mercurial \
        subversion \
        wget \
        htop

ENV PATH /opt/conda/bin:$PATH

CMD [ "/bin/bash" ]

# Leave these args here to better use the Docker build cache
RUN wget --quiet https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh -O miniconda.sh && \
    mkdir -p /opt && \
    sh miniconda.sh -b -p /opt/conda && \
    ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
    echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
    echo "conda activate base" >> ~/.bashrc && \
    find /opt/conda/ -follow -type f -name '*.a' -delete && \
    find /opt/conda/ -follow -type f -name '*.js.map' -delete && \
    /opt/conda/bin/conda clean -afy

RUN conda create -n stringdist python=3.8.3 && \
    conda install -y -n stringdist pep8 pylint numpy scipy notebook

RUN conda config --add channels c4aarch64 && \
    conda config --add channels conda-forge && \
    conda install -y -n stringdist -c numba numba

CMD conda activate stringdist

Anyway not really an issue! Numba is now working fine on M1 on Docker.

Ah great, thanks for reporting back, glad you got something working.

1 Like