dockermacosanacondaapple-siliconmicromamba

Docker from micromamba base image is hanging at " Transaction starting" step when installing packages on Apple Silicon (osx-arm64)


I'm trying to build docker images on my MacBook Pro which is using a M2 processor. I've created images from this Dockerfile several times on my previous MacBook Pro which used an Intel processor.

I'm currently running iTerm2 w/ Rosetta to simulate an Intel processor.

$ arch
i386

Here is my build command:

docker build --build-arg ENV_NAME=${ENV_NAME} -t ${TAG} -f Dockerfile ../../

Here is my Dockerfile:

# v2024.3.10
# =================================
FROM --platform=linux/amd64 mambaorg/micromamba:latest

ARG ENV_NAME

SHELL ["/usr/local/bin/_dockerfile_shell.sh"]

WORKDIR /tmp/

# Data
USER root
RUN mkdir -p /volumes/
RUN mkdir -p /volumes/input
RUN mkdir -p /volumes/output
RUN mkdir -p /volumes/database

# Retrieve VEBA repository
RUN mkdir -p veba/
USER $MAMBA_USER
COPY --chown=$MAMBA_USER:$MAMBA_USER ./install/ veba/install/
COPY --chown=$MAMBA_USER:$MAMBA_USER ./bin/ veba/bin/
COPY --chown=$MAMBA_USER:$MAMBA_USER ./VERSION veba/VERSION
COPY --chown=$MAMBA_USER:$MAMBA_USER ./LICENSE veba/LICENSE

# Fix: 
# critical libmamba Download error (28) Timeout was reached
# [https://conda.anaconda.org/bioconda/linux-64/blast-2.13.0-hf3cf87c_0.tar.bz2]
# Operation too slow. Less than 30 bytes/sec transferred the last 60 seconds

ARG MAMBA_NO_LOW_SPEED_LIMIT=1

# Build .condarc
RUN echo "channel_priority: flexible" >> ~/.condarc
RUN echo "channels:" >> ~/.condarc
RUN echo "  - conda-forge" >> ~/.condarc
RUN echo "  - bioconda" >> ~/.condarc
RUN echo "  - jolespin" >> ~/.condarc

# Install dependencies
RUN micromamba install -y -n base -f veba/install/environments/${ENV_NAME}.yml && \
    micromamba clean -a -y -f

# Add environment scripts to environment bin
RUN cp -rf veba/bin/* /opt/conda/bin/ && \
    ln -sf /opt/conda/bin/scripts/*.py /opt/conda/bin/ && \
    ln -sf /opt/conda/bin/scripts/*.r /opt/conda/bin/

ENTRYPOINT ["/usr/local/bin/_entrypoint.sh"]

I've also tried this in terminal without Rosetta:

$ arch
arm64

The weirdest part about this is that I was able to build an image from this conda environment yaml last night but now it's not working. The full list of Docker images I'm building are using the following yaml files: https://github.com/jolespin/veba/tree/main/install/environments

Does anyone have any idea on how I can build these Docker images on Apple Silicon?


Solution

  • I figured it out. You need to do 3 things if you encounter this issue:

    1. Use FROM --platform=linux/amd64

    2. Open your terminal or iTerm using Rosetta:

    enter image description here

    1. Go to Docker > Settings > General > Use Rosetta for x86_64/amd64 emulation on Apple Silicon (Turn it on):

    enter image description here